AoC - Day 1

:date: 2023-12-01 12:00

Part One

This was so easy using simple unix command line tricks that I really was not properly prepared for the onslaught of complexity that was to come. But for the first challenge, this was easy.

$ for N in $(cat $I);do echo $N|tr -dc '[0-9]'|sed 's/^\(.\)$/\1\1/'|sed 's/^\(.\).*\(.\)$/\1\2\n/';done|awk '{X+=$1}END{print X}'


Part One

This solution is fun - I use the unix rev command which returns the input lines in their original line order but with the characters backwards. And then to save trouble I just look for the backwards versions of the numbers (eno, owt, eerht, etc).

This looks more complicated than it is. It's really just busy listing all the numbers twice.

$ paste -d '' <(for N in $(cat $I);do echo $N|sed 's/\(one\|two\|three\|four\|five\|six\|seven\|eight\|nine\)/@\1@/'|sed -e s/@one@/1/g -e s/@two@/2/g -e s/@three@/3/g -e s/@four@/4/g -e s/@five@/5/g -e s/@six@/6/g -e s/@seven@/7/g -e s/@eight@/8/g -e s/@nine@/9/g |tr -dc '[0-9\n]'|sed 's/^\(.\).*$/\1/';done) <(for N in $(rev $I);do echo $N|sed 's/\(eno\|owt\|eerht\|ruof\|evif\|xis\|neves\|thgie\|enin\)/@\1@/'|sed -e s/@eno@/1/g -e s/@owt@/2/g -e s/@eerht@/3/g -e s/@ruof@/4/g -e s/@evif@/5/g -e s/@xis@/6/g -e s/@neves@/7/g -e s/@thgie@/8/g -e s/@enin@/9/g|tr -dc '[0-9\n]'|sed 's/^\(.\).*$/\1/';done)|awk '{X+=$1}END{print X}'