def check_cases(): for i, (key, value) in enumerate(test_cases.items()): print('Testing Case {}'.format(i)) # Instantiate intcode computer computer = IntcodeComputer(key) # Run intcode computer computer.compute() print(computer.final_state) # Convert the expected output into a list so # that we can compare it to our intcode # computer's output test_state = intcode_to_list(value) assert computer.final_state == test_state print('===================') print('👍')
def brute_force(program: str, output: int): for noun in range(100): for verb in range(100): # Instantiate intcode computer computer = IntcodeComputer(program) # Replace values at addresses 1 and 2 as per # puzzle instructions computer.edit_input(1, noun) computer.edit_input(2, verb) # We then run the program for the current # noun, verb pair try: computer.compute() if computer.final_state[0] == output: print('{}, {} produces the desired output {}'.format( noun, verb, desired_output)) return noun, verb except IndexError: continue print('Unable to find a suitable noun, verb pair.') return False
# !/usr/bin/python import os dir_path = os.path.dirname(os.path.realpath(__file__)) puzzle_input_path = os.path.join(dir_path, 'puzzle_input.txt') from intcode_computer import IntcodeComputer if __name__ == "__main__": total_fuel_requirement = 0 with open(puzzle_input_path) as f: intcode_program_list = f.readlines() for program in intcode_program_list: print('Running Intcode Computer...') computer = IntcodeComputer(program) # First we apply the changes to the puzzle input according # to the instructions in the puzzle computer.edit_input(1, 12) computer.edit_input(2, 2) # We then run the program to process # the intcode program computer.compute() computer.pprint_output() computer.print_position_0()