15 lines
397 B
Python
15 lines
397 B
Python
|
with open("input.txt","r") as f:
|
||
|
masses = [int(x) for x in f.read().split('\n')]
|
||
|
|
||
|
def fuel_required(mass):
|
||
|
return mass // 3 - 2
|
||
|
|
||
|
def fuel_required_recursive(mass):
|
||
|
fuel = mass // 3 - 2
|
||
|
if fuel <= 0:
|
||
|
return 0
|
||
|
return fuel + fuel_required_recursive(fuel)
|
||
|
|
||
|
part1 = sum([fuel_required(mass) for mass in masses])
|
||
|
part2 = sum([fuel_required_recursive(mass) for mass in masses])
|
||
|
print(part1, part2)
|