Browse Source

Day 1

master
mid-kid 1 year ago
commit
5541394383
  1. 39
      d01.sh
  2. 1000
      d01_input.txt

39
d01.sh

@ -0,0 +1,39 @@
#!/bin/sh
sum=0
while read line; do
num1="$(echo "$line" | sed -n 's/^[^0-9]*\([0-9]\).*/\1/p')"
num2="$(echo "$line" | sed -n 's/.*\([0-9]\)[^0-9]*$/\1/p')"
sum=$(( $sum + $num1$num2 ))
done < d01_input.txt
echo "$sum"
sum=0
while read line; do
line1="$(echo "$line" | sed \
-e 's/\(one\|two\|three\|four\|five\|six\|seven\|eight\|nine\)/%\1%/' \
-e 's/%one%/1/' \
-e 's/%two%/2/' \
-e 's/%three%/3/' \
-e 's/%four%/4/' \
-e 's/%five%/5/' \
-e 's/%six%/6/' \
-e 's/%seven%/7/' \
-e 's/%eight%/8/' \
-e 's/%nine%/9/')"
line2="$(echo "$line" | sed \
-e 's/.*\(one\|two\|three\|four\|five\|six\|seven\|eight\|nine\)/%\1%/' \
-e 's/%one%/1/' \
-e 's/%two%/2/' \
-e 's/%three%/3/' \
-e 's/%four%/4/' \
-e 's/%five%/5/' \
-e 's/%six%/6/' \
-e 's/%seven%/7/' \
-e 's/%eight%/8/' \
-e 's/%nine%/9/')"
num1="$(echo "$line1" | sed -n 's/^[^0-9]*\([0-9]\).*/\1/p')"
num2="$(echo "$line2" | sed -n 's/.*\([0-9]\)[^0-9]*$/\1/p')"
sum=$(( $sum + $num1$num2 ))
done < d01_input.txt
echo "$sum"

1000
d01_input.txt

File diff suppressed because it is too large
Loading…
Cancel
Save