mid-kid
1 year ago
commit
5541394383
2 changed files with 1039 additions and 0 deletions
@ -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" |
File diff suppressed because it is too large
Loading…
Reference in new issue