Created
December 2, 2019 14:19
-
-
Save tapionx/b831354b90363dea88ffd6ed61eefac4 to your computer and use it in GitHub Desktop.
Advent of Code 2019 #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for noun in range(99): | |
for verb in range(99): | |
with open('2_input.txt', 'r') as f: | |
input_program = [int(x) for x in f.read().strip().split(',')] | |
input_program[1] = noun | |
input_program[2] = verb | |
def execute_intcode(input_program): | |
program_counter = 0 | |
while program_counter < len(input_program) and input_program[program_counter] != 99: | |
#print(program_counter, input_program[program_counter]) | |
opcode = input_program[program_counter] | |
input1_address = input_program[program_counter + 1] | |
input2_address = input_program[program_counter + 2] | |
output_address = input_program[program_counter + 3] | |
if opcode == 1: | |
input_program[output_address] = input_program[input1_address] + input_program[input2_address] | |
if opcode == 2: | |
input_program[output_address] = input_program[input1_address] * input_program[input2_address] | |
program_counter += 4 | |
return input_program | |
if execute_intcode(input_program)[0] == 19690720: | |
print(noun, verb) | |
print(100 * noun + verb) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment