def solve_part_2(puzzle_input): # instructions = [ "NOT A T", "OR T J", "NOT B T", "OR T J", "NOT C T", "OR T J", "AND D J", "NOT E T", "NOT T T", "OR H T", "AND T J", ] runtime = IntCodeRuntime() runtime.set_program(puzzle_input) runtime.run() print(runtime.get_ascii_output()) runtime.input_ascii("\n".join(instructions)) runtime.input_ascii("\nRUN\n") runtime.run() output = runtime.get_output() for num in output: try: print(chr(num), end="") except: return num return ""
def solve_part_2(puzzle_input): amplifier_configurations = permutations(range(5, 10)) highest_signal = 0 best_configuration = None for configuration in amplifier_configurations: #print(configuration) signal = 0 amp_runtimes = [] for amp_i in range(5): amp_config = configuration[amp_i] program = puzzle_input[:] runtime = IntCodeRuntime() runtime.set_program(program) runtime.input_number(amp_config) amp_runtimes.append(runtime) while all(r.get_status() != IntCodeStatus.HALTED for r in amp_runtimes): for amp_i, runtime in enumerate(amp_runtimes): if runtime.get_status() == IntCodeStatus.HALTED: break runtime.input_number(signal) runtime.run() signal = runtime.get_output()[0] if signal > highest_signal: highest_signal = signal best_configuration = configuration return highest_signal
def solve_part_2(puzzle_input): # Not hard to do the paths by hand PART_2_PATH = "R,12,L,8,L,4,L,4,L,8,R,6,L,6,R,12,L,8,L,4,L,4,L,8,R,6,L,6,L,8,L,4,R,12,L,6,L,4,R,12,L,8,L,4,L,4,L,8,L,4,R,12,L,6,L,4,R,12,L,8,L,4,L,4,L,8,L,4,R,12,L,6,L,4,L,8,R,6,L,6" sub_paths = { "A": "R,12,L,8,L,4,L,4", "B": "L,8,L,4,R,12,L,6,L,4", "C": "L,8,R,6,L,6" } main_path = "A,C,A,C,B,A,B,A,B,C" logic_input = [main_path, sub_paths["A"], sub_paths["B"], sub_paths["C"], "n"] program = puzzle_input[:] program[0] = 2 runtime = IntCodeRuntime() runtime.set_program(program) for line in logic_input: for char in line: runtime.input_number(ord(char)) runtime.input_number(ord("\n")) runtime.run() return runtime.get_output()[-1]
def solve_part_1(puzzle_input): runtime = IntCodeRuntime() runtime.set_program(puzzle_input[:]) runtime.run() output = runtime.get_output() ascii_output = "".join(chr(code) for code in output) print(ascii_output) scaffold_map = [] current_line = [] for char in ascii_output: if char == "\n": scaffold_map.append(current_line) current_line = [] else: current_line.append(char) alignment_sum = 0 for j in range(1,len(scaffold_map)-2): for i in range(1, len(scaffold_map[j])-1): if scaffold_map[j][i] == "#" and \ scaffold_map[j][i+1] == "#" and scaffold_map[j+1][i] == "#" and \ scaffold_map[j][i-1] == "#" and scaffold_map[j-1][i] == "#": alignment_sum += j * i return alignment_sum
def solve_part_1(puzzle_input, system_id): runtime = IntCodeRuntime() runtime.set_program(puzzle_input) runtime.input_number(system_id) runtime.run() for line in runtime.get_output(): print(line)
def solve_part_1(puzzle_input): runtime = IntCodeRuntime() runtime.set_program(puzzle_input[:]) runtime.run() output = runtime.get_output() tile_ids = output[2::3] count_blocks = 0 for tile_id in tile_ids: if tile_id == 2: count_blocks += 1 return count_blocks
def solve_part_2(puzzle_input): puzzle_input[0] = 2 runtime = IntCodeRuntime() runtime.set_program(puzzle_input[:]) screen = [[None for _ in range(45)] for __ in range(24)] segment_display = 0 while runtime.get_status() != IntCodeStatus.HALTED: runtime.run() output = runtime.get_output() segment_display = refresh_screen(screen, segment_display, output) #joystick_input = input("Joystick Input: ") sleep(1 / 60) joystick_input = get_joystick_input(screen) joystick_signal = joystick_signal_map[joystick_input] runtime.input_number(joystick_signal) return "Game Over"
def solve(puzzle_input, start_square=0): painted = set() grid = defaultdict(int) runtime = IntCodeRuntime() runtime.set_program(puzzle_input[:]) x, y = (0, 0) grid[(x, y)] = start_square dx, dy = NORTH while runtime.get_status() != IntCodeStatus.HALTED: runtime.input_number(grid[(x, y)]) runtime.run() output = runtime.get_output() assert len(output) == 2 grid[(x, y)] = output[0] painted.add((x, y)) dx, dy = get_new_direction((dx, dy), output[1]) x, y = (x + dx, y + dy) return len(painted), grid
def solve_part_1(puzzle_input): amplifier_configurations = permutations(range(5)) highest_signal = 0 best_configuration = None for configuration in amplifier_configurations: #print(configuration) signal = 0 for amp_i in range(5): amp_config = configuration[amp_i] program = puzzle_input[:] runtime = IntCodeRuntime() runtime.set_program(program) runtime.input_number(amp_config) runtime.input_number(signal) runtime.run() signal = runtime.get_output()[0] if signal > highest_signal: highest_signal = signal best_configuration = configuration return highest_signal
def solve_part_1(puzzle_input): runtime = IntCodeRuntime() runtime.set_program(puzzle_input[:]) runtime.input_number(1) runtime.run() return "\n" + "\n".join(map(str, runtime.get_output()))