def test_run_intcode(initial: List, expected: List) -> None: """ Run a sample Intcode program and verify the final state of the program after calling halt. """ program = Intcode(initial) program.run() assert program.get_program() == expected
def first_star() -> int: """ Load and run the provided intcode program, then return the value in index 0. """ initial = _get_initial_list() initial[1] = 12 initial[2] = 2 program = Intcode(initial) program.run() return program.get_program()[0]
def second_star(target: int) -> int: """ Find the "noun" and "verb" - integers from 0-99 - to replace input indices 1 and 2 - that when running the program, produces the target value in index 0. Load list from file once; copy as needed to iterate over different input parameters. """ initial = _get_initial_list() for noun in range(0, 100): for verb in range(0, 100): modified = copy.deepcopy(initial) modified[1] = noun modified[2] = verb program = Intcode(modified) program.run() if program.get_program()[0] == target: return noun * 100 + verb raise RuntimeError("Can't find suitable inputs")
def test_multiplication_parameter_modes(): program = Intcode([1002, 4, 3, 4, 33]) program.run() assert program.get_program() == [1002, 4, 3, 4, 99]
def test_intcode_input(): input_ = random.randint(0, 100) program = Intcode([3, 0, 4, 0, 99], [input_]) program.run() assert program.get_program() == [input_, 0, 4, 0, 99]
def test_negative_values(): program = Intcode([1101, 100, -1, 4, 0]) program.run() assert program.get_program() == [1101, 100, -1, 4, 99]