advent-of-code/2019-python/output/day_01.py

41 lines
758 B
Python
Raw Normal View History

2023-12-19 18:34:03 +01:00
from output import answer
n = 1
title = "The Tyranny of the Rocket Equation"
@answer(1, "Total fuel requirements are {}")
2023-12-19 18:34:03 +01:00
def part_1(o):
return o[0]
@answer(2, "Total fuel requirements are {} including fuel costs")
2023-12-19 18:34:03 +01:00
def part_2(o):
return o[1]
def solve(data):
lines = list(map(int, data.split()))
p1 = sum(n // 3 - 2 for n in lines)
p2 = 0
for fuel in lines:
rem = fuel
while rem > 0:
cost = rem // 3 - 2
2023-12-19 18:34:03 +01:00
p2 += max(0, cost)
rem = max(0, cost)
2023-12-19 18:34:03 +01:00
return p1, p2
if __name__ == "__main__":
2023-12-19 18:34:03 +01:00
with open("./input/01.txt", "r") as f:
inp = f.read().strip()
inp = solve(inp)
a = part_1(inp)
b = part_2(inp)
assert a == 3393938
assert b == 5088037