def run_phase(seq): input_ = 0 for phase in seq: ic = IntCode(raw, [phase, input_]) ic.execute() input_ = ic.outputs[0] return input_
def part2(): for i in range(100): for j in range(100): ic = IntCode(raw) ic.ins[1], ic.ins[2] = i, j ic.execute() if ic.ins[0] == 19690720: return 100 * i + j
def amplifier_controller_software_part_1(arr): highest_signal = float('-inf') perms = itertools.permutations(range(5)) for perm in perms: last_output = 0 for i in range(5): program = IntCode(arr, inputs=[perm[i], last_output]) output = program.execute(pause_on_output=True) last_output = output highest_signal = max(highest_signal, last_output) return highest_signal
def travel_ship(): output = [] computer = IntCode(state, []) while not computer.is_completed(): try: out = computer.execute(input_func) if out == 10: print(''.join(list(map(chr, output)))) output = [] else: output += [out] except IndexError: break
def run(x): ic = IntCode(raw, x) ic.execute() return ic.outputs[-1]
def part1(): ic = IntCode(raw) ic.ins[1], ic.ins[2] = 12, 2 ic.execute() return ic.ins[0]
#%% import numpy as np from intcode import IntCode from utils import load raw = load("day13.txt", split=",", parseint=True) # %% ic = IntCode(raw) ic.execute() out = np.array(ic.outputs).reshape((-1, 3)) print(np.sum(out[:, 2] == 2)) #%% Part 2 class Arcade(IntCode): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.img = None self.score = 0 self.ball = None self.pad = None def run_game(self, input_=None): if input_ is not None: self.inputs.append(input_) out = self.execute() self.process() return out def process(self):
def list_join(l, sep): new_list = [] for i in l: new_list += [i, sep] return new_list[:-1] # map generation view = [] line = [] start = None computer = IntCode(state, []) while not computer.is_completed(): try: out = computer.execute(part1_input) if out == 10: view.append(line) line = [] else: line.append(chr(out)) if chr(out) in "^<v>": direction = ['^', '<', 'v', '>'].index(chr(out)) start = (len(view), len(line) - 1) except IndexError: pass view.pop() #accounts for extra newline at end for row in view: print(''.join(row))
def main(): text_input = get_raw_input() int_code = IntCode(text_input) int_code.add_input(1) int_code.execute()
from intcode import IntCode with open("13.txt", "r") as f: state = list(map(int, f.readline().strip().split(","))) computer = IntCode(state, []) x = y = tile = 0 mapping = {} while not computer.is_completed(): try: x = computer.execute([]) y = computer.execute([]) tile = computer.execute([]) mapping[(x, y)] = tile except IndexError: break state[0] = 2 computer = IntCode(state, []) ball_x = paddle_x = points = 0 def joystick(): if ball_x < paddle_x: return -1 elif ball_x > paddle_x: return 1 else:
def diagnostic_program(arr, inputs): program = IntCode(arr, inputs) output = program.execute() return output
def gravity_assist_program_part_1(arr, noun, verb): prog = IntCode(arr) prog.update(1, noun) prog.update(2, verb) prog.execute() return prog.get(0)
(0, -1): [(1, 0), (-1, 0)], (1, 0): [(0, 1), (0, -1)] } for i in range(2): direction = (0, 1) x = y = 0 painted = {} painted[(x, y)] = i computer = IntCode(state, []) inputs = deque() while not computer.is_completed(): panel_col = not ((x, y) not in painted or painted[(x, y)] == 0) inputs.append(panel_col) try: colour = computer.execute(input_func) dir_val = computer.execute(input_func) except IndexError: break painted[(x, y)] = colour direction = dirs[direction][dir_val] x += direction[0] y += direction[1] if i == 0: part_1 = len(painted) x_vals = [x[0] for x in painted.keys()] y_vals = [y[0] for y in painted.keys()] min_x = abs(min(x_vals)) max_x = max(x_vals)