aboutsummaryrefslogtreecommitdiff
path: root/2016/04/puzzle-1.sh
blob: 67ccb7c31c341cc1e83304d41af012f5217275ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 <input | awk '{ s += $0 } END { print s }'