aboutsummaryrefslogtreecommitdiff
path: root/2015/02/puzzle-1.awk
blob: e316ba25148c29411af4880b23ee141e00c98a89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env -S 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 * $2
	y = $2 * $3
	z = $1 * $3

	sum += (2 * x) + (2 * y) + (2 * z) + min(x, y, z)
}
END   { print sum }