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