diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-11-30 12:23:17 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-11-30 12:23:17 +0100 |
commit | f3e3e3e354b87f4ce27bd74bf14cec05d06974b6 (patch) | |
tree | 112352e9c3ba5d5d924036def2b5f853d3f8dc28 /2015/02/puzzles.awk | |
parent | 4742dd73046c53cff7fe54deee58358c3b193206 (diff) |
Lots of cleanup and stuff
Diffstat (limited to '2015/02/puzzles.awk')
-rw-r--r-- | 2015/02/puzzles.awk | 27 |
1 files changed, 27 insertions, 0 deletions
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 } |