aboutsummaryrefslogtreecommitdiff
path: root/2015/02
diff options
context:
space:
mode:
Diffstat (limited to '2015/02')
-rw-r--r--2015/02/Makefile1
-rwxr-xr-x2015/02/puzzle-1.awk6
-rwxr-xr-x2015/02/puzzle-2.awk6
-rw-r--r--2015/02/puzzles.awk27
4 files changed, 34 insertions, 6 deletions
diff --git a/2015/02/Makefile b/2015/02/Makefile
new file mode 100644
index 0000000..3e0defd
--- /dev/null
+++ b/2015/02/Makefile
@@ -0,0 +1 @@
+include ../../Makefiles/awk.mk
diff --git a/2015/02/puzzle-1.awk b/2015/02/puzzle-1.awk
index e316ba2..5c05d31 100755
--- a/2015/02/puzzle-1.awk
+++ b/2015/02/puzzle-1.awk
@@ -1,7 +1,6 @@
-#!/usr/bin/env -S awk -f
+#!/usr/bin/awk -f
-function min(a, b, c)
-{
+function min(a, b, c) {
if (a <= b && a <= c)
return a
if (b <= a && b <= c)
@@ -11,6 +10,7 @@ function min(a, b, c)
BEGIN { FS = "x" }
{
+ # START PART 1
x = $1 * $2
y = $2 * $3
z = $1 * $3
diff --git a/2015/02/puzzle-2.awk b/2015/02/puzzle-2.awk
index e031b94..450aed9 100755
--- a/2015/02/puzzle-2.awk
+++ b/2015/02/puzzle-2.awk
@@ -1,7 +1,6 @@
-#!/usr/bin/env -S awk -f
+#!/usr/bin/awk -f
-function min(a, b, c)
-{
+function min(a, b, c) {
if (a <= b && a <= c)
return a
if (b <= a && b <= c)
@@ -16,5 +15,6 @@ BEGIN { FS = "x" }
z = $1 + $1 + $3 + $3
sum += $1 * $2 * $3 + min(x, y, z)
+ # END PART 2
}
END { print sum }
diff --git a/2015/02/puzzles.awk b/2015/02/puzzles.awk
new file mode 100644
index 0000000..b7b35e1
--- /dev/null
+++ b/2015/02/puzzles.awk
@@ -0,0 +1,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 }