def __init__(self): self.computer = intcode_computer.IntcodeComputer(initial_state=intcode_program_list) # offset from 0 for easy tkinter drawing self.x = 100 self.y = 100 self.last_direction_attempted = None self.current_on_oxygen = False self.known_space = {(self.x, self.y): 1} # dict of position tuples, value is wall/floor/oyxgen self.current_path = [(self.x, self.y)] self.oxygen = None self.oxygen_default_path_length = None
NUM_AMPS = 5 initial_state = intcode_program_list # initial_state = [3, 15, 3, 16, 1002, 16, 10, 16, 1, 16, 15, 15, 4, 15, 99, 0, 0] # initial_state = [3, 26, 1001, 26, -4, 26, 3, 27, 1002, 27, 2, 27, 1, 27, 26, 27, 4, 27, 1001, 28, -1, 28, 1005, 28, 6, 99, 0, 0, 5] # initial_state = [3, 52, 1001, 52, -5, 52, 3, 53, 1, 52, 56, 54, 1007, 54, 5, 55, 1005, 55, 26, 1001, 54, # -5, 54, 1105, 1, 12, 1, 53, 54, 53, 1008, 54, 0, 55, 1001, 55, 1, 55, 2, 53, 55, 53, 4, # 53, 1001, 56, -1, 56, 1005, 56, 6, 99, 0, 0, 0, 0, 10] phase_settings = list(itertools.permutations(x for x in range(5, 10))) best_output = 0 for phase_setting in phase_settings: print(f"Testing settings {phase_setting}") amplifiers = [] input_signal = 0 for i in range(0, NUM_AMPS): new_amp = ic.IntcodeComputer(initial_state=initial_state, friendly_name=str(i)) amplifiers.append(new_amp) res = next(new_amp.run_computer()) assert res is True # Computer asks for phase setting new_amp.next_input = phase_setting[i] res = next(new_amp.run_computer()) assert res is True # Computer asks for input signal finished_execution = False while finished_execution is False: for amp in amplifiers: amp.next_input = input_signal res = next(amp.run_computer() ) # Run computer, until it produces an output assert type( res
tkinter.Button(tkinter_root, bg=color).grid( row=y, column=x, sticky=tkinter.N + tkinter.S + tkinter.E + tkinter.W) tkinter_root.update_idletasks() tkinter_root.update() input_path = "input.txt" with open(input_path) as input_file: input_string = input_file.read() intcode_program_list = [int(x) for x in input_string.split(sep=',')] intcode_program_list[0] = 2 # Part 2 computer = intcode_computer.IntcodeComputer(initial_state=intcode_program_list) root_window = tkinter.Tk() res = True output = [] curr_step_of_program = 0 initial_display = False joystick_direction = 0 # left is -1, right is 1 paddle_curr_x = -1 ball_curr_x = -1 while res is not False: # Run game res = computer.run_computer() if res is True: # print("Needs input...")
import intcode_computer.intcode_computer as ic_c input_path = "input.txt" with open(input_path) as input_file: initial_state = input_file.read() initial_state = initial_state.split(sep=',') initial_state = [int(x) for x in initial_state] # print(initial_state) # initial_state = [1002,4,3,4,33] # initial_state = [3,9,8,9,10,9,4,9,99,-1,8] # equals to 8 positional # initial_state = [3,9,7,9,10,9,4,9,99,-1,8] # less than 8 positional # initial_state = [3,3,1108,-1,8,3,4,3,99] # equal 8, imediate # initial_state = [3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31, # 1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104, # 999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99] # input, outpout is += 8 computer = ic_c.IntcodeComputer() computer.set_state(initial_state) output = True returns = [] while output is not False: output = next(computer.run_computer(input_val=5)) returns.append(output) print(returns) print(computer._state)
import sys import os import intcode_computer.intcode_computer as ic # input_path = "test1.txt" input_path = "input.txt" intcode_computer = ic.IntcodeComputer() with open(input_path) as input_file: intcode_program_str = input_file.read() intcode_program_list = [int(x) for x in intcode_program_str.split(sep=',')] intcode_computer.set_state(intcode_program_list) if input_path == "input.txt": # Frig results as problem intcode_computer.set_noun(12) intcode_computer.set_verb(2) result = True res_list = [] while result is not False: result = next(intcode_computer.run_computer()) res_list.append(result) print(f"Part 1 result: {res_list}") print (intcode_computer._state[0]) # # Part 2 # for noun in range(0, 100): # for verb in range(0, 100):