Esempio n. 1
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    drone = Drone(intcode)
    drone.execute_for_grid(82, 82)
    drone.command_line_display()
    return sum(affected for k,affected in drone.tractor_area.items() if k[0] <= 49 and k[1] <= 49)
Esempio n. 2
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    arc = Arcade(intcode)
    arc.execute()
    print()
    print(sum(1 for x in arc.screen.values() if x == 2))
Esempio n. 3
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    pr = PaintingRobot(intcode)
    pr.execute()
    paint_registration_id(pr.painting_area)
    return pr.painting_area
Esempio n. 4
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    drone = Drone(intcode)
    for i in range(1, 5):
        result = drone.explore(i, (0, 0))
        if result:
            return
Esempio n. 5
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    drone = Drone(intcode)
    # drone.manual_execute()
    x, y = drone.search_first_len(100)
    # drone.command_line_display()
    return x * 10000 + y
Esempio n. 6
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    queues = [queue.Queue() for _ in range(50)]
    network_computers = []
    for network_id in range(50):
        network_computers.append(
            NetworkComputer(_id=network_id,
                            intcode=copy.deepcopy(intcode),
                            queues=queues))
    workers = [
        threading.Thread(target=computer.execute)
        for computer in network_computers
    ]
    [worker.start() for worker in workers]
    [worker.join() for worker in workers]
Esempio n. 7
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    robot = VacuumRobot(intcode)
    robot.execute()
    return robot.colllected_dust
Esempio n. 8
0
                self.direction = self.DIRECTIONS['up']
        if direction == self.RIGHT:
            if self.direction == self.DIRECTIONS['up']:
                self.direction = self.DIRECTIONS['right']
            elif self.direction == self.DIRECTIONS['right']:
                self.direction = self.DIRECTIONS['down']
            elif self.direction == self.DIRECTIONS['down']:
                self.direction = self.DIRECTIONS['left']
            elif self.direction == self.DIRECTIONS['left']:
                self.direction = self.DIRECTIONS['up']

        px, py = self.position
        dx, dy = self.direction
        self.position = (px + dx, py + dy)


if __name__ == '__main__':
    program = read_input()

    # part 1
    panel = Panel(initial_color=Panel.BLACK)
    robot = Robot(program, panel)
    robot.run()
    print(f'Number of plates painted: {panel.painted_plates_count()}')

    # part 2
    panel = Panel(initial_color=Panel.WHITE)
    robot = Robot(program, panel)
    robot.run()
    panel.draw_to_stdout()
Esempio n. 9
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    intcode_computer = IntcodeComputer(intcode, lambda: 2,
                                       lambda x: print(f"BOOST keycode: {x}"))
    intcode_computer.execute()
Esempio n. 10
0
def create_grid(ascii: str) -> np.array:
    grid = np.zeros((len(ascii.splitlines()), len(ascii.splitlines()[0])), dtype=str)
    for i, line in enumerate(ascii.splitlines()):
        for j, val in enumerate(line):
            grid[i][j] = val
    return grid


def compute_intersections_value(grid: np.array) -> int:
    total = 0
    for i in range(1, grid.shape[0] - 1):
        for j in range(1, grid.shape[1] - 1):
            if (
                grid[i][j] == "#"
                and grid[i + 1][j] == "#"
                and grid[i - 1][j] == "#"
                and grid[i][j + 1] == "#"
                and grid[i][j - 1] == "#"
            ):
                total += i * j
    return total


if __name__ == "__main__":
    program = Program(read_input("./day17_input.txt"))
    ascii = get_ascii(program)
    grid = create_grid(ascii)

    print(f"Solution for part 1:{compute_intersections_value(grid)}")
Esempio n. 11
0
    return grid


def test_corners(program: Program, x: int, y: int) -> bool:
    for xx, yy in [(x, y), (x + 99, y), (x, y + 99), (x + 99, y + 99)]:
        program.reset()
        program.add_input(xx)
        program.add_input(yy)
        if next(program.operate()) != 1:
            return False
    return True


def part2(program: Program) -> Tuple[int, int]:
    # values below found graphically
    for x in range(800, 1100):
        for y in range(200, 500):
            if test_corners(program, x, y):
                return x, y
    raise ValueError("not found")


if __name__ == "__main__":
    puzzle = read_input("./day19_input.txt")
    program = Program(puzzle)
    grid = scan(program)
    print(f"Solution for part 1: {grid.sum()}")
    # I mixed up x and y somehow
    x, y = part2(program)
    print(f"Solution for part 2: {y*10000 + x}")
Esempio n. 12
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    pr = PaintingRobot(intcode)
    pr.execute()
    return len(pr.painting_area.keys())
Esempio n. 13
0
        return self.grid.get_position_of(self.BALL_TILE)

    def paddle_position(self):
        return self.grid.get_position_of(self.PADDLE_TILE)

    def move_joystick(self, direction):
        assert (direction in [
            self.JOYSTICK_LEFT, self.JOYSTICK_NEUTRAL, self.JOYSTICK_RIGHT
        ])

        self.joystick_direction = direction

    def _remove_check_for_quarters(self, program):
        program[0] = 2
        return program

    def _debug(self, message):
        if self.debug:
            print('[DEBUG] ' + message)


if __name__ == '__main__':
    arcade = Arcade(read_input())

    arcade.run()
    print(f'Block tiles on screen: {arcade.grid.count_of_tiles_of_type(2)}')

    arcade = Arcade(read_input(), play_for_free=True)
    arcade.run()
    print(f'Score: {arcade.score}')
Esempio n. 14
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    droid = Droid(intcode)
    droid.execute()
Esempio n. 15
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    arc = Arcade(intcode)
    arc.execute()
    print(f"Final score: {arc.score}")
Esempio n. 16
0
def main(intcode: List[int] = None):
    if not intcode:
        intcode = read_input(input_file=_INPUT_FILE)
    droid = SpringDroid(intcode)
    droid.execute()
    print(''.join(droid.result))