aboutsummaryrefslogtreecommitdiff
path: root/2019/01/puzzles.awk
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-14 18:32:07 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-14 18:32:07 +0100
commit2f97464bff64652faa8038e392ced279e03dd607 (patch)
treeb6549b956ad47640662585e7447352525102285b /2019/01/puzzles.awk
parent2542891f652dc09727788047256c330eaaae6a02 (diff)
Add 2019 day 1 solutions
Diffstat (limited to '2019/01/puzzles.awk')
-rw-r--r--2019/01/puzzles.awk14
1 files changed, 14 insertions, 0 deletions
diff --git a/2019/01/puzzles.awk b/2019/01/puzzles.awk
new file mode 100644
index 0000000..4abe899
--- /dev/null
+++ b/2019/01/puzzles.awk
@@ -0,0 +1,14 @@
+#!/usr/bin/awk -f
+
+function fuel(n)
+{
+ n = int(n / 3) - 2
+ # START PART 1
+ return n
+ # END PART 1 START PART 2
+ return n <= 0 ? 0 : n + fuel(n)
+ # END PART 2
+}
+
+{ n += fuel($1) }
+END { print n } \ No newline at end of file