aboutsummaryrefslogtreecommitdiff
path: root/2023/02/puzzle-2.awk
blob: 8c19409633c294ea299ee79014bdd26ba984ec7e (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 = 0; g = 0; b = 0

	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)
				r = n
			else if (c == "green" && n > g)
				g = n
			else if (c == "blue" && n > b)
				b = n
		}
	}

	sum += r * g * b
}

END {
	print sum
}