AdventOfCode/2019/day1.py

18 lines
491 B
Python
Raw Normal View History

2019-12-02 13:59:18 +01:00
def get_fuel(mass):
2019-12-15 15:55:57 +01:00
return max(0, mass // 3 - 2)
2019-12-02 13:59:18 +01:00
needed_fuel = 0
with open("day1.txt", "rt") as input_file:
for line in input_file.readlines():
mass = int(line.strip())
fuel = get_fuel(mass)
2019-12-15 15:55:57 +01:00
# Part 2. Comment from line 11 to 14 included for part 1.
fuel_for_fuel = fuel
while fuel_for_fuel > 0:
fuel_for_fuel = get_fuel(fuel_for_fuel)
fuel += fuel_for_fuel
2019-12-02 13:59:18 +01:00
needed_fuel += fuel
print(needed_fuel)