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) 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])