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.
33 lines
920 B
33 lines
920 B
import unittest
|
|
import os
|
|
|
|
class Day1(unittest.TestCase):
|
|
inputfile = os.path.join(os.path.dirname(__file__), "day1_input")
|
|
|
|
def calc_fuel(self, mass):
|
|
fuel = mass // 3 - 2
|
|
if(fuel > 0):
|
|
return fuel + self.calc_fuel(fuel)
|
|
else:
|
|
return 0
|
|
|
|
def test_day1a(self):
|
|
fuel = 0
|
|
with open(self.inputfile) as fp:
|
|
value = fp.readline()
|
|
while value:
|
|
fuel += int(value) // 3 - 2
|
|
value = fp.readline()
|
|
self.assertEqual(fuel, 3402609)
|
|
|
|
def test_day1b(self):
|
|
with open(self.inputfile) as fp:
|
|
line = fp.readline()
|
|
sumfuel = 0
|
|
while line:
|
|
sumfuel += self.calc_fuel(int(line))
|
|
line = fp.readline()
|
|
self.assertEqual(sumfuel, 5101025)
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main() |