summary refs log tree commit diff homepage
path: root/2018/day02-1.sh
blob: 695959f0f86b76e01d9658f3c582e0c4b5293d3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
alpha='a b c d e f g h i j k l m n o p q r s t u v w x y z'
twos() {
	for a in $alpha; do
		tr -c -d "$a\n" < $1 \
			| grep -n '^..$' \
			| cut -d ':' -f 1
	done | sort -u | wc -l
}
threes() {
	for a in $alpha; do
		tr -c -d "$a\n" < $1 \
			| grep -n '^...$' \
			| cut -d ':' -f 1
	done | sort -u | wc -l
}
input=$(mktemp)
cat > $input
echo $(( $(twos $input) * $(threes $input) ))
rm $input