summary refs log tree commit diff homepage
path: root/2022/day06.awk
blob: b6827805fd4ed2e5432b82729b7d6fbdf9caae0a (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
27
28
function repeats(s, i) {
	for (i = 1; i <= length(s); i++) {
		for (j = i+1; j <= length(s); j++) {
			if (substr(s, i, 1) == substr(s, j, 1)) return 1;
		}
	}
	return 0;
}
{
	for (i = 1; i <= length; i++) {
		c1 = c2;
		c2 = c3;
		c3 = c4;
		c4 = substr($1, i, 1);
		if (c1 == c2 || c1 == c3 || c1 == c4) continue;
		if (c2 == c3 || c2 == c4) continue;
		if (c3 == c4) continue;
		if (i < 4) continue;
		print i;
		break;
	}
	for (i = 1; i+14 <= length; i++) {
		s = substr($1, i, 14);
		if (repeats(s)) continue;
		print 13+i;
		break;
	}
}