def get_map(cls, program: typing.List[int], draw_mode=False) -> "Map": computer = IntComputer(program, wait_after_output=True, wait_for_input=True) visited = defaultdict(int) droid_map = Map() steps = 0 while not computer.finished and steps < 6000: direction = droid_map.get_best_direction(visited) steps += 1 computer.inputs = [direction] computer.run() while not computer.waiting: computer.run() output = computer.output if output == OUTPUT_WALL: droid_map.wall_hit([NORTH, SOUTH, WEST, EAST][direction - 1]) if output == OUTPUT_FREE: [droid_map.north, droid_map.south, droid_map.west, droid_map.east][ direction - 1 ]() droid_map.set_position(droid_map.position, FREE) if output == OUTPUT_OXYGEN: [droid_map.north, droid_map.south, droid_map.west, droid_map.east][ direction - 1 ]() droid_map.set_position(droid_map.position, OXYGEN) visited[droid_map.position] += 1 if draw_mode: droid_map.render() return droid_map
def day05_01(): program = get_number_list_from_file("./puzzles/05/puzzle.txt") computer = IntComputer(memory=program) computer.inputs = [1] computer.run() print(f"conditioner unit (part 1) {computer.output}")
def day05_02(): program = get_number_list_from_file("./puzzles/05/puzzle.txt") computer = IntComputer(memory=program) computer.inputs = [5] computer.run() print(f"thermal radiator controller (part 2) {computer.output}")