parent
f79f5589f6
commit
ecd8ac4d7b
@ -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…
Reference in new issue