def thrust_for_phase_settings(self, program, phases): value = 0 for phase in phases: ic = aoc.Intcode(program[:], inputs=[phase, value]) ic.run() value = ic.outputs[-1] return value
def calculate(self, input_data): memory = list(input_data) memory[1] = 12 memory[2] = 2 intcode = aoc.Intcode(memory) intcode.run() return intcode.memory[0]
def calculate(self, input_data): orig_memory = list(input_data) for noun in range(100): for verb in range(100): intcode = aoc.Intcode(memory[0] + [noun,verb] + memory[3:]) intcode.run() if intcode.memory[0] == 19690720: return 100*noun + verb return None
def thrust_for_phase_settings(self, program, phases): amps = [aoc.Intcode(program[:], inputs=[phase]) for phase in phases] amps[0].inputs.append(0) thrust = None amp = 0 while amps[-1]: next_amp = (amp + 1) % len(amps) if amps[amp]: try: if not amps[amp].run_one(): amps[amp] = None elif len(amps[amp].outputs): signal = amps[amp].outputs.pop(0) if next_amp == 0: thrust = signal if amps[next_amp]: amps[next_amp].inputs.append(signal) except EOFError: pass amp = next_amp return thrust
def paint(self, program, initial_color=0): robot = (0, 0) ship = {robot: initial_color} facing = 'U' turn = { 'U': [('L', (-1, 0)), ('R', (1, 0))], 'L': [('D', (0, 1)), ('U', (0, -1))], 'D': [('R', (1, 0)), ('L', (-1, 0))], 'R': [('U', (0, -1)), ('D', (0, 1))], } running = True ic = aoc.Intcode(program) while running: ic.inputs.append(ship.get(robot, 0)) while running and len(ic.outputs) < 2: running = ic.run_one() if ic.outputs: ship[robot] = ic.outputs.pop(0) if ic.outputs: (facing, delta) = turn[facing][ic.outputs.pop(0)] robot = (robot[0] + delta[0], robot[1] + delta[1]) return ship
def calculate(self, input_data): ic = aoc.Intcode(list(input_data), inputs=[1]) ic.run() return ic.outputs
def calculate(self, input_data): intcode = aoc.Intcode(list(input_data), inputs=[5]) intcode.run() return intcode.outputs