From 86071ef703bd3e3cd55a4ca93668d157d1941363 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 5 Dec 2022 21:29:43 +0100 Subject: Add 2016 day 4 solutions --- 2016/04/puzzle-1.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 2016/04/puzzle-1.sh (limited to '2016/04/puzzle-1.sh') diff --git a/2016/04/puzzle-1.sh b/2016/04/puzzle-1.sh new file mode 100755 index 0000000..67ccb7c --- /dev/null +++ b/2016/04/puzzle-1.sh @@ -0,0 +1,15 @@ +#!/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 \ + | awk "{ s = s \$2 } END { if (s == \"$cksum\") print $sid }" +done