aboutsummaryrefslogtreecommitdiff
path: root/2022/06/puzzles.awk
blob: 2a5394979d07d72e50e5b3dfb4b67b5f463fb8d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/gawk -f

BEGIN {
	RS = "[a-z]"
	# START PART 1
	COUNT = 4
	# END PART 1 START PART 2
	COUNT = 14
	# END PART 2
}
NR > COUNT {
	for (i = 2; i <= length(a); i++)
		a[i - 1] = a[i]
	delete a[length(a)]
}
{ a[(NR == 1 ? 0 : length(a)) + 1] = RT }
NR > COUNT {
	for (i in a) {
		if (_a[a[i]]++ == 1) {
			delete _a
			next
		}
	}
	print NR
	exit
}