Day 1 (Bash)

This commit is contained in:
Logan G 2023-12-02 23:09:26 -07:00
parent 7a8642e304
commit dce4c59b44
Signed by: logan
GPG key ID: E328528C921E7A7A
7 changed files with 53 additions and 0 deletions

1
day1/answer1 Normal file
View file

@ -0,0 +1 @@
55208

1
day1/answer2 Normal file
View file

@ -0,0 +1 @@
54578

14
day1/day1p1.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
SUM=0
while read f; do
TEMP1="$(echo ${f//[a-z]})"
TEMP2="${TEMP1:0:1}${TEMP1:0-1}"
for i in $TEMP2; do
echo $SUM + $i
SUM=$(( $SUM + $i ))
done
done < input
echo $SUM

25
day1/day1p2.sh Executable file
View file

@ -0,0 +1,25 @@
#!/bin/bash
SUM=0
while read f; do
TEMP1=($(echo $f | awk '{
while (match($0, /([0-9]|one|two|three|four|five|six|seven|eight|nine)/)) {
print substr($0, RSTART, RLENGTH)
$0 = substr($0, RSTART + RLENGTH)
}
}' | sed -e 's/[0-9]/\0 /g;s/one/\0 /g;s/two/\0 /g;s/three/\0 /g;s/four/\0 /g;s/five/\0 /g;s/six/\0 /;s/seven/\0 /;s/eight/\0 /;s/nine/\0 /g'))
TEMP2=($(echo $f | rev | awk '{
while (match($0, /([0-9]|eno|owt|eerht|ruof|evif|xis|neves|thgie|enin)/)) {
print substr($0, RSTART, RLENGTH)
$0 = substr($0, RSTART + RLENGTH)
}
}' | sed -e 's/[0-9]/\0 /g;s/eno/\0 /g;s/owt/\0 /g;s/eerht/\0 /g;s/ruof/\0 /g;s/evif/\0 /g;s/xis/\0 /;s/neves/\0 /;s/thgie/\0 /;s/enin/\0 /g'))
FIRST=$( echo ${TEMP1[0]} | sed -e 's/one/1/g;s/two/2/g;s/three/3/g;s/four/4/g;s/five/5/g;s/six/6/g;s/seven/7/g;s/eight/8/g;s/nine/9/g')
LAST=$( echo ${TEMP2[0]} | rev | sed -e 's/one/1/g;s/two/2/g;s/three/3/g;s/four/4/g;s/five/5/g;s/six/6/g;s/seven/7/g;s/eight/8/g;s/nine/9/g')
echo $f: $FIRST$LAST
SUM=$(( $SUM + $FIRST$LAST ))
#sleep 1
done < input
echo $SUM

4
day1/sample1 Normal file
View file

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

7
day1/sample2 Normal file
View file

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

1
day1/sample3 Normal file
View file

@ -0,0 +1 @@
dftzgsdc19threesevennine3twonevl