aboutsummaryrefslogtreecommitdiff
path: root/2015/02/puzzles.awk
blob: b7b35e106bb4422e635e7a0b4e9c98fe7e0c58be (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
#!/usr/bin/awk -f

function min(a, b, c) {
	if (a <= b && a <= c)
		return a
	if (b <= a && b <= c)
		return b
	return c
}

BEGIN { FS = "x" }
{
	# START PART 1
	x = $1 * $2
	y = $2 * $3
	z = $1 * $3

	sum += (2 * x) + (2 * y) + (2 * z) + min(x, y, z)
	# END PART 1 START PART 2
	x = $1 + $1 + $2 + $2
	y = $2 + $2 + $3 + $3
	z = $1 + $1 + $3 + $3

	sum += $1 * $2 * $3 + min(x, y, z)
	# END PART 2
}
END   { print sum }