import os from typing import Dict def get_code() -> Dict[str, str]: inputfile = os.path.join(os.path.dirname(__file__), "input/day06_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(): orbs = get_code() cnt = 0 for orb in orbs.keys(): n = orb cnt -= 1 while n: n = orbs.get(n) cnt += 1 assert cnt == 241064 def test_day6b(): orbs = 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) assert len(k) == 418