diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-12-05 21:29:43 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-12-05 21:29:43 +0100 |
commit | 86071ef703bd3e3cd55a4ca93668d157d1941363 (patch) | |
tree | a807ca0aaea74a26fd04af6432e8db1f6ada79bc /2016/04/puzzles.sh | |
parent | 04197d46e899873af5478b4d5ccaf1579fe0b6f8 (diff) |
Add 2016 day 4 solutions
Diffstat (limited to '2016/04/puzzles.sh')
-rw-r--r-- | 2016/04/puzzles.sh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/2016/04/puzzles.sh b/2016/04/puzzles.sh new file mode 100644 index 0000000..d874c75 --- /dev/null +++ b/2016/04/puzzles.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# This is slow, but it’s fun! That’s what counts! + +while IFS='[]' read -r line cksum; do + sid=`echo $line | grep -o '[0-9]*'` + echo $line \ + | tr -d -- '-0-9\n' \ + | sed 's/./&\n/g' \ + | sort \ + | uniq -c \ + | sort -k1nr \ + | head -n5 \ +# START PART 1 + | awk "{ s = s \$2 } END { if (s == \"$cksum\") print $sid }" +done <input | awk '{ s += $0 } END { print s }' +# END PART 1 START PART 2 + | awk "{ s = s \$2 } END { if (s == \"$cksum\") print \"$line\" }" +done <input | \ + while read -r line; do + for i in `seq 25`; do + echo $line | tr $(printf %${i}s | tr ' ' '.')\a-z a-za-z + done + # The call to head(1) allows us to exit the moment we find the + # first match. + done | grep north | grep -o '[0-9]*' | head -n1 +# END PART 2 |