import unittest import os from .comp import OpcodeComputer import itertools class Day7(unittest.TestCase): inputfile = os.path.join(os.path.dirname(__file__), "input/day7_input") def test_day7a(self): com = OpcodeComputer(self.inputfile) configs = itertools.permutations(range(5), 5) res: int = 0 for conf in configs: sig: int = 0 for phase in conf: sig = int(list(com.process_op([phase, sig]))[0]) res = sig if sig > res else res self.assertEqual(res, 21000) def test_day7b(self): """ Shoutout to OverjoyedBanana for his helpful solution https://www.reddit.com/r/adventofcode/comments/e7om28/2019_day_7_part_2_python3_help_with/fa3bh4w/ https://pastebin.com/cyLTHUYV """ com = OpcodeComputer(self.inputfile) res: int = 0 for config in itertools.permutations(range(5, 10), 5): sig: int = 0 buffer = [[conf] for conf in config] comps = list(map(com.process_op, buffer)) try: while True: for i in range(5): buffer[i].append(sig) sig = int(next(comps[i])) except StopIteration: pass res = sig if sig > res else res self.assertEqual(res, 61379886)