AoC - Day 4

:date: 2023-12-04 12:00

Part One

Can this be done with a unix command line? Yes it can!

$ while read L;do(sed 's/^.*:  *\(.*\) |.*$/\1/'<<<$L|sed 's/  */\n/g'; sed 's/^.*| *\(.*\) *$/\1/'<<<$L|sed 's/  */\n/g')|sort -n|uniq -c|grep '^ *2 '|wc -l|awk '{print int(2**($1-1))}';done<$I|awk '{X+=$1}END{print X}'

25651

Part Two

And this too. Main loop still in Bash but with Awk now doing the heavy lifting with the complexifying loops. Not a problem!

$ while read L;do (sed 's/^.*:  *\(.*\) |.*$/\1/'<<<$L|sed 's/  */\n/g'; sed 's/^.*| *\(.*\) *$/\1/'<<<$L|sed 's/  */\n/g')|sort -n|uniq -c|grep '^ *2 '|wc -l;done<$I|awk '{C[NR]++;for (d=1;d<=C[NR];d++){for(i=NR+1;i<=NR+$1;i++){C[i]++}}}END{for(i in C)T+=C[i];print T}'

19499881