loading...

re: Advent of Code 2019 Solution Megathread - Day 1: The Tyranny of the Rocket Equation VIEW POST

FULL DISCUSSION
 

Here's my cleaned up Python solution!

masses = map(int, open('data.txt', 'r').readlines())

# part 1
def calc_fuel(mass):
    return mass // 3 - 2

print(sum([calc_fuel(m) for m in masses]))

# part 2
def calc_additional_fuel(mass):
    total, fuel = 0, calc_fuel(mass)
    while fuel > 0:
        total += fuel
        fuel = calc_fuel(fuel)
    return total

print(sum([calc_additional_fuel(m) for m in masses]))
code of conduct - report abuse