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.
35 lines
937 B
35 lines
937 B
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)
|
|
|