aboutsummaryrefslogtreecommitdiff
path: root/2023/02/puzzle-1.awk
blob: 8d689435d89999cd48e4f47dca4faba8c1e91b7c (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
29
30
31
#!/usr/bin/awk -f

BEGIN {
	FS = "[;:] "

	r = 12
	g = 13
	b = 14
}

{
	for (i = 2; i <= NF; i++) {
		split($i, xs, /, /)
		for (j in xs) {
			split(xs[j], ys, / /)
			n = ys[1]
			c = ys[2]

			if (c == "red" && n > r || c == "green" && n > g ||
					c == "blue" && n > b)
				next
		}
	}

	sub(/Game /, "", $1)
	sum += $1
}

END {
	print sum
}