aboutsummaryrefslogtreecommitdiff
path: root/2015/02/puzzle-2.awk
blob: 450aed929a06167312f34e01176042f1e918db6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/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" }
{
	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 }