Skip to content
advent of code 2019

day 11

space police

approach

only part 2 is written. simulation drives the robot with the day 9 interpreter: it reads two outputs at a time (a colour to paint the current panel and a turn), turns by adding ±π/2 to its heading, moves one panel, and appends the colour under it to the program's input list. panels live in a defaultdict(int), so unpainted ones read as black.

part2 starts on a white panel, finds the bounding box of the painted panels and prints them as # and spaces. there is no part1: simulation can start on black, but nothing counts the panels it painted.

the trick

the heading is an angle, and cos and sin rounded to ints turn it into a unit step.

python
def rotate(rads):
    return (int(cos(rads)),int(sin(rads)))