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.
AdventOfCode19/days/test_day07.py

44 lines
1.1 KiB

import itertools
import os
from . import OpcodeComputer
inputfile = os.path.join(os.path.dirname(__file__), "input/day07_input")
def test_day7a():
com = OpcodeComputer(inputfile)
configs = itertools.permutations(range(5), 5)
res: int = 0
for conf in configs:
sig: int = 0
for phase in conf:
sig = list(com.process_op([phase, sig]))[0]
res = sig if sig > res else res
assert res == 21000
def test_day7b():
"""
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(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 = next(comps[i])
except StopIteration:
pass
res = sig if sig > res else res
assert res == 61379886