From 2f97464bff64652faa8038e392ced279e03dd607 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 14 Dec 2024 18:32:07 +0100 Subject: Add 2019 day 1 solutions --- 2019/01/.gitignore | 1 + 2019/01/Makefile | 1 + 2019/01/puzzles.awk | 14 ++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 2019/01/.gitignore create mode 100644 2019/01/Makefile create mode 100644 2019/01/puzzles.awk (limited to '2019') diff --git a/2019/01/.gitignore b/2019/01/.gitignore new file mode 100644 index 0000000..f28b4ae --- /dev/null +++ b/2019/01/.gitignore @@ -0,0 +1 @@ +puzzles-[12].awk \ No newline at end of file diff --git a/2019/01/Makefile b/2019/01/Makefile new file mode 100644 index 0000000..e7d8b6c --- /dev/null +++ b/2019/01/Makefile @@ -0,0 +1 @@ +include ../../Makefiles/awk.mk \ No newline at end of file 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 -- cgit v1.2.3