From 85a67d26fa2a740abe952a3389abbb325e4bef54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Ytterstr=C3=B6m?= Date: Tue, 21 Nov 2023 09:43:48 +0100 Subject: [PATCH] Solve 2019:01 "The Tyranny of the Rocket Equation" --- 2019-python/output/day_01.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 2019-python/output/day_01.py diff --git a/2019-python/output/day_01.py b/2019-python/output/day_01.py new file mode 100644 index 0000000..64a49f7 --- /dev/null +++ b/2019-python/output/day_01.py @@ -0,0 +1,32 @@ +from output import answer, puzzleinput + +n = 1 +title = "The Tyranny of the Rocket Equation" + + +@puzzleinput(n) +def parse_input(data): + return list(map(int, data.split())) + + +@answer(1, "Total fuel requirements are {}") +def part_1(lines): + return sum(n // 3 - 2 for n in lines) + + +@answer(2, "Total fuel requirements are {} including fuel costs") +def part_2(lines): + s = 0 + for fuel in lines: + rem = fuel + while rem > 0: + cost = rem // 3 - 2 + s += max(0, cost) + rem = max(0, cost) + return s + + +if __name__ == "__main__": + parsed = parse_input() + part_1(parsed) + part_2(parsed)