You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdventOfCode19/days/test_day01.py

27 lines
650 B

import os
inputfile = os.path.join(os.path.dirname(__file__), "input/day01_input")
def calc_fuel(mass):
fuel = mass // 3 - 2
return fuel + calc_fuel(fuel) if fuel > 0 else 0
def test_day1a():
fuel = 0
with open(inputfile) as fp:
for _, line in enumerate(fp):
fuel += int(line) // 3 - 2
assert fuel == 3402609
def test_day1b():
sumfuel = 0
with open(inputfile) as fp:
for _, line in enumerate(fp):
sumfuel = 0
while line:
sumfuel += calc_fuel(int(line))
line = fp.readline()
assert sumfuel == 5101025