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/day1.py

27 lines
822 B

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