Skip to content
advent of code 2019

day 13

care package

approach

solved years later than the rest, with a reworked interpreter in the shared intcode folder. it's now an Intcode class that keeps memory, ip and the relative base on the object, takes a deque for input, and raises InputInterrupt when it needs input that isn't there. because all the state is on the object, calling exec() again resumes where it stopped.

play collects outputs in threes and draws them into a grid; the (-1, 0) position is the score instead. part 1 counts the block tiles after the program halts. part 2 sets address 0 to 2 to play for free, and every time the program asks for input it moves the paddle towards the ball's column. the score left at the end is the answer. a debug flag redraws the board in the terminal each turn.

the trick

the paddle just follows the ball, one step per input.

python
except InputInterrupt:
    if debug:
        time.sleep(0.05)
        os.system("clear")
        print(format(grid))
    if ballc < dashc:
        inpt.append(-1)
    elif ballc > dashc:
        inpt.append(1)
    else:
        inpt.append(0)