def test_1_pt1(self): self.assertEqual([3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50], run_program( [1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50]))
def test_5_pt1(self): self.assertEqual([30, 1, 1, 4, 2, 5, 6, 0, 99], run_program([1, 1, 1, 4, 99, 5, 6, 0, 99]))
def test_4_pt1(self): self.assertEqual([2, 4, 4, 5, 99, 9801], run_program([2, 4, 4, 5, 99, 0]))
def test_3_pt1(self): self.assertEqual([2, 3, 0, 6, 99], run_program([2, 3, 0, 3, 99]))
def test_2_pt1(self): self.assertEqual([2, 0, 0, 0, 99], run_program([1, 0, 0, 0, 99]))
import sys from pathlib import Path import numpy as np from one import parse_program, run_program if __name__ == "__main__": program = parse_program(Path(__file__).parent / "input.txt") for sub_i, (sub_cmd, _) in enumerate(program): sub_cmd = {"nop": "jmp", "jmp": "nop"}.get(sub_cmd) if sub_cmd is None: continue exit_code, accumulator = run_program(program, substitute={sub_i: sub_cmd}) if exit_code == 0: break print(accumulator)