Find my full solution repo here

“I got 99 problems but an Intcode puzzle ain’t one.” Jay-Z, if he were doing Advent of Code.

My Robot

The main objects that you need to track for this puzzle are the robot and the hull. For the robot, I wrote a class that tracks position and a direction vector. I tracked the hull colors using a 2d list. To determine how many squares were painted, I tracked tuples of positions in a list and then got the length of the list.

To make sure that the hull data structure was large enough to track the color info, I checked the size requirements before each move and grew the lists if necessary.

def check_hull_size(hull, robot):
    next_pos = robot.get_next_pos()
    if next_pos[0] < 0:
        for row in hull:
            row.insert(0, 0)
        return (True, "right")
    if next_pos[0] > len(hull[0]) - 1:
        for row in hull:
    if next_pos[1] < 0:
        hull.insert(0, [0 for i in range(0, len(hull[0]))])
        return (True, "down")
    if next_pos[1] > len(hull) - 1:
        hull.append([0 for i in range(0, len(hull[0]))])
    return (False, "dummy")

The return value tells the main program loop whether the hull data structure was shifted. If so, the main program then shifts all the painted square data as well.

Here is my main loop:

program = prep_intcode_program("./input/day11.txt")
computer = IntcodeComputer(program.copy())
robot = Robot()
hull = [[0]]
painted_squares = []
output = ("dummy", "dummy")
while output[1] != "halt":
    next_color = computer.compute([get_current_color(hull, robot)])[0]
    paint_square(hull, robot, next_color, painted_squares)
    output = computer.compute([])
    next_turn = output[0]
    if next_turn == 0:
    shifted = check_hull_size(hull, robot)
    if shifted[0]:
        painted_squares = shift_painted_squares(painted_squares, shifted[1])

Find my full solution repo here