aboutsummaryrefslogtreecommitdiff
path: root/2024/05/puzzle-1.awk
blob: 59616c91e6540a75a39b715d60fd72b206e351a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/gawk -f

BEGIN { FS = "[|,]" }

/\|/ { rules[$1][$2] = 1 }
/,/ {
	delete seen
	for (i = 1; i <= NF; i++) {
		for (j in seen) {
			if (j in rules[$i])
				next
		}
		seen[$i] = 1
	}
	mid += $(i / 2)
}

END { print mid }