import int_comp as ic from collections import namedtuple Position = namedtuple("Position", "x y") memory = [int(i) for i in input().split(',')] memory.extend([0]*1000) comp = ic.Computer(memory, 0) directions = ["up", "right", "down", "left"] dir_idx = 0 tiles = {Position(0,0) : 0} # position : color colored_tiles = set() colored_tiles_list = [] robot_pos = Position(0, 0) while True: outputs, state = comp.compute_result() color, direction = outputs # paint tile current_color = tiles.get(robot_pos, 0) if current_color != color: tiles[robot_pos] = color colored_tiles.add(robot_pos) print("Painted", robot_pos, color) # adjust robot's direction if direction == 0: # turn left 90 degress
# fill the tiles with oxygen for t in tiles_to_fill: tiles_map[t[0]][t[1]] = '*' if print_: for t in tiles_map: print(''.join(t)) print() return minutes_passed program = [int(i) for i in input().split(',')] comp = ic.Computer(program) output, state = comp.compute_result() start_pos = Tile(0,0,'.') robot = Robot(comp, start_pos) tiles = dfs_explore(robot) tiles_map = print_tiles(tiles, start_pos) destination = next((t for t in tiles if t.state == '*')) print(destination) path = find_path_bfs(Tile(0,0,'.'), destination, tiles) print_tiles(path, path[0]) print("Path length:", len(path)) # Oxygen spreading
def print_tiles(tiles): print() for row in tiles: print(''.join(row)) def count_tiles(tiles, id): count = 0 for tile in tiles: count += tile.count(id) return count input_sequence = [int(i) for i in input().split(',')] comp = ic.Computer(input_sequence, 0) instructions, state = comp.compute_result() draw_instructions = [] for i in range(0, len(instructions), 3): draw_instructions.append( DrawInstruction(instructions[i], instructions[i + 1], instructions[i + 2])) width = max(draw_instructions, key=lambda d: d.x).x height = max(draw_instructions, key=lambda d: d.y).y tiles = [[' ' for _ in range(width + 1)] for _ in range(height + 1)] # fill tiles for d in draw_instructions: if d.id == 0: