def main2(): program = open_program('input') program[0] = 2 computer = IntCode(program, default_memory=8000) halted = False grid = defaultdict(lambda: 0) while not halted: halted = computer.run() while computer.has_output(): x_pos = computer.get_output() y_pos = computer.get_output() tile_id = computer.get_output() if tile_id == 3: paddle_x = x_pos elif tile_id == 4: ball_x = x_pos grid[Point(x_pos, y_pos)] = tile_id print_grid(grid) if paddle_x > ball_x: user_input = -1 elif paddle_x < ball_x: user_input = 1 else: user_input = 0 computer.add_input(user_input) return grid[Point(-1, 0)]
def main(): program = open_program('input') computer = IntCode(program, default_memory=8000) # J = (~A or ~B or ~C) and D computer._inputs.extend(string_to_ascii('NOT A T\n')) computer._inputs.extend(string_to_ascii('NOT B J\n')) computer._inputs.extend(string_to_ascii('OR T J\n')) computer._inputs.extend(string_to_ascii('NOT C T\n')) computer._inputs.extend(string_to_ascii('OR T J\n')) computer._inputs.extend(string_to_ascii('AND D J\n')) # computer._inputs.extend(string_to_ascii('WALK\n')) # J = J and (D and (E | H)) computer._inputs.extend(string_to_ascii('NOT E T\n')) computer._inputs.extend(string_to_ascii('NOT T T\n')) computer._inputs.extend(string_to_ascii('OR H T\n')) computer._inputs.extend(string_to_ascii('AND D T\n')) computer._inputs.extend(string_to_ascii('AND T J\n')) computer._inputs.extend(string_to_ascii('RUN\n')) computer.run() for char in computer._outputs: try: print(chr(char), end='') except ValueError: return char
def part1(): program = open_program('input') computers = [make_computer(program, count) for count in range(50)] y_value = None while not y_value: for computer in computers: if not computer._inputs: computer._inputs.append(-1) computer.run() while computer._outputs: address = computer.get_output() x = computer.get_output() y = computer.get_output() if address == 255: y_value = y break else: computers[address].add_input(x) computers[address].add_input(y) return y_value
def main(filename='input'): program = open_program(filename) computer = IntCode(program, default_memory=8000) location = Point(0, 0) grid = defaultdict(lambda: 0) grid[location] = GridSpace.DROID grid, oxygen_location = run_moves(computer, grid, location) print_grid(grid) return oxygen_location, escape(grid, Point(-16, 14))
def main(): program = open_program('input') computer = IntCode(program, default_memory=8000) halted = False grid = defaultdict(lambda: 0) while not halted: halted = computer.run() while computer.has_output(): x_pos = computer.get_output() y_pos = computer.get_output() tile_id = computer.get_output() grid[Point(x_pos, y_pos)] = tile_id print_grid(grid) return len([item for item in grid.values() if item == 2])
def part1(): program = open_program('input') # computer = IntCode(program) count = 0 for y in range(50): for x in range(50): computer = IntCode(program[:]) computer.add_input(x) computer.add_input(y) computer.run() output = computer.get_output() if output: count += 1 else: pass # print(x,y) return count
def main(initial_color=0, filename='input'): program = open_program(filename) computer = IntCode(program) halted = False grid = defaultdict(lambda: 0) location = Point(0, 0) grid[location] = initial_color facing = Direction.UP while not halted: computer.add_input(grid[location]) halted = computer.run() color = computer.get_output() direction = computer.get_output() grid[location] = color location, facing = move_robot(location, facing, direction) print_grid(grid) return len(grid.keys())
def main(): program = open_program('input') computers = [make_computer(program, count) for count in range(50)] naty = None natx = None last_y = None while True: idle = True for computer in computers: if not computer._inputs: computer._inputs.append(-1) else: idle = False computer.run() while computer._outputs: address = computer.get_output() x = computer.get_output() y = computer.get_output() if address == 255: natx = x naty = y else: computers[address].add_input(x) computers[address].add_input(y) if idle and natx and naty: if last_y == naty: break computers[0].add_input(natx) computers[0].add_input(naty) last_y = naty return last_y
def part2(): program = tuple(open_program('input')) # computer = IntCode(program) base_y = 475 base_x = 975 for i in range(100): last = 0 for j in range(100): count = 0 # grid = defaultdict(int) for y in range(base_y + j, base_y + j + 100): for x in range(base_x + i, base_x + i + 100): output = check_point(program, Point(x, y)) if output: count += 1 # grid[Point(x, y)] = 1 # print('#', end='') else: pass # print('.', end='') # print(x,y) # print('') if count == 10000: print(Point(base_x + i, base_y + j)) print(Point(x, y)) return (base_x + i) * 10000 + (base_y + j) else: print(count, Point(x, y)) if last > count: break else: last = count
def main(filename='input'): program = open_program(filename) # print(part1(program)) return part2(program[:])
from intcode import IntCode, open_program from typing import Iterator import random def make_instruction(instruction: str) -> Iterator[int]: return map(ord, instruction + '\n') if __name__ == "__main__": program = open_program('input') computer = IntCode(program, default_memory=8000) inputs = [ make_instruction('west'), make_instruction('west'), make_instruction('north'), make_instruction('take space heater'), make_instruction('south'), make_instruction('east'), make_instruction('south'), make_instruction('take festive hat'), make_instruction('south'), make_instruction('take sand'), make_instruction('north'), make_instruction('east'), make_instruction('take whirled peas'), make_instruction('west'), make_instruction('north'), make_instruction('east'), make_instruction('south'),