path = networkx.shortest_path(self.graph, tile, t)
            length = len(path)
            if length > furthest:
                furthest = length
        return furthest


def plot_map(walls, oxygen, path):
    x, y = zip(*[[w.x, w.y] for w in walls.values()])
    plt.plot(x, y, 'x')
    plt.plot(oxygen[0], oxygen[1], 'o')
    plt.plot(0, 0, '+')
    pathx, pathy = zip(*path)
    plt.plot(pathx, pathy)
    plt.legend(['Walls', 'oxygen', 'origin', 'path'])
    plt.show()


if __name__ == "__main__":
    computer = intcode.IntcodeComputer(
        intcode.read_intcode_input_file('input.txt'), [])
    repair_droid = RepairDroid(computer)
    oxygen = repair_droid.map_corridors()
    repair_droid.generate_graph(oxygen)
    # networkx.draw(repair_droid.graph)
    path_to_oxygen = repair_droid.path_to_oxygen(oxygen)
    print("Distance to oxygen = ", len(path_to_oxygen) - 1)
    minutes = repair_droid.fill_oxygen(oxygen) - 1
    print("mintutes to fill oxygen : ", minutes)
    plot_map(repair_droid.walls, oxygen, path_to_oxygen)
    plt.show()
Ejemplo n.º 2
0
            break
        else:
            print('error')
            return 0
    return intcode


def process_opcode(opcode):
    opcode = str(opcode)
    mode = opcode[-2:]
    p_modes = []
    for p in range(3, 6):
        if p <= len(opcode):
            p_modes.append(1 if opcode[-p] == '1' else 0)
        else:
            p_modes.append(0)
    return opcode_instructions[int(mode)], [
        parameter_modes[p] for p in p_modes
    ]


code = process_code(intcode)
print(code)

from intcode import read_intcode_input_file, IntcodeComputer

code = read_intcode_input_file('input.txt')
IC = IntcodeComputer(code, [])
code = IC.run()
print(code)
Ejemplo n.º 3
0
        elif self.direction == 'Right':
            self.x += 1
        elif self.direction == 'Down':
            self.y -= 1
        else:
            self.x -= 1

    def set_new_direction(self, dir):
        if self.direction == 'Up':
            self.direction = 'Left' if dir == 0 else 'Right'
        elif self.direction == 'Right':
            self.direction = 'Up' if dir == 0 else 'Down'
        elif self.direction == 'Down':
            self.direction = 'Right' if dir == 0 else 'Left'
        else:
            self.direction = 'Down' if dir == 0 else 'Up'


if __name__ == "__main__":
    program = intcode.read_intcode_input_file('input.txt')
    hull = Hull(100)
    robot = Robot(hull, program, start_on_white=True)
    robot.run()
    painted = 0
    for panel in hull.panels.values():
        if panel.times_painted > 0:
            painted += 1
    print(painted)
    hull.show_hull()