day 1 - faster

main
Codinget 1 year ago
parent 7ee787f976
commit b19dc7ad22
  1. 6
      day1/day1.sh

@ -45,6 +45,12 @@ for number in $(cat "$1" | sed s/[^0-9]//g); do
done
printf "part 1: %d\n" $sum
sum=0
for number in $(cat "$1" | sed s/one/o1e/g | sed s/two/t2o/g | sed s/three/t3hee/g | sed s/four/f4ur/g | sed s/five/f5ve/g | sed s/six/s6x/g | sed s/seven/s7ven/g | sed s/eight/e8ght/g | sed s/nine/n9ne/g | sed s/[^0-9]//g); do
sum=$((sum+${number:0:1}*10+${number:${#number}-1:${#number}}))
done
printf "part 2 (faster alt): %d\n" $sum
sum=0;
for line in $(cat "$1"); do
number="$(replacedigits $line)"

Loading…
Cancel
Save