Added day 6

master
fettlaus 6 years ago
parent f79f5589f6
commit ecd8ac4d7b
  1. 2
      advent.py
  2. 1
      days/__init__.py
  3. 35
      days/day6.py
  4. 1444
      days/input/day6_input

@ -12,6 +12,8 @@ def suite():
suite.addTest(Day4('test_day4b')) suite.addTest(Day4('test_day4b'))
suite.addTest(Day5('test_day5a')) suite.addTest(Day5('test_day5a'))
suite.addTest(Day5('test_day5b')) suite.addTest(Day5('test_day5b'))
suite.addTest(Day6('test_day6a'))
suite.addTest(Day6('test_day6b'))
return suite return suite

@ -3,4 +3,5 @@ from .day2 import Day2
from .day3 import Day3 from .day3 import Day3
from .day4 import Day4 from .day4 import Day4
from .day5 import Day5 from .day5 import Day5
from .day6 import Day6
from .comp import OpcodeComputer from .comp import OpcodeComputer

@ -0,0 +1,35 @@
import unittest
import os
from typing import Dict
class Day6(unittest.TestCase):
def get_code(self) -> Dict[str, str]:
inputfile = os.path.join(os.path.dirname(__file__), "input/day6_input")
with open(inputfile) as fp:
return {x[1].rstrip(): x[0] for x in
(y.split(')') for y in fp.readlines())}
def test_day6a(self):
orbs = self.get_code()
cnt = 0
for orb in orbs.keys():
n = orb
cnt -= 1
while n:
n = orbs.get(n)
cnt += 1
self.assertEqual(cnt, 241064)
def test_day6b(self):
orbs = self.get_code()
c = orbs['YOU']
k = []
while c:
k.append(c)
c = orbs.get(c)
c = orbs['SAN']
while c:
k.remove(c) if c in k else k.append(c)
c = orbs.get(c)
self.assertEqual(len(k), 418)

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save