aboutsummaryrefslogtreecommitdiff
path: root/2015/02/puzzle-1.awk
diff options
context:
space:
mode:
Diffstat (limited to '2015/02/puzzle-1.awk')
-rwxr-xr-x2015/02/puzzle-1.awk20
1 files changed, 20 insertions, 0 deletions
diff --git a/2015/02/puzzle-1.awk b/2015/02/puzzle-1.awk
new file mode 100755
index 0000000..e316ba2
--- /dev/null
+++ b/2015/02/puzzle-1.awk
@@ -0,0 +1,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 }