Advent of Code 2019

The story of my slow descent into madness

View on GitHub
11 December 2019

Day 11: Space Police

by Simon Berger


Links:

Whenever the intcode machine comes back I really want to start these posts by saying something like “and here we go again”, but that’s really uninspired and gets annoying after a while. I don’t really have any other way of starting off today’s post though, so… Here we go again!

This time we’re dealing with code that has an external state. To read from or write to this external state using the input and output instructions is a pretty nifty idea. The puzzle is basically a combination of day 8’s image rendering part and the intcode machine and I appreciate when puzzles build on each other like that and that’s all I have to say on the matter.

I made a really silly mistake while working on the first part. To get the last two outputs from my intcode interpreter I took the first two items you get by reversing over the output. This method does get the last two items, but they’re in reverse order… I ended up treating the colour as the rotation and vice versa and because their values are both either 0 or 1 they are practically indistinguishable. I only realised this after I had (accidentally) solved the problem by using a different approach for getting the output. I made it so the interpreter’s output buffer is always cleared after retrieving it. This way, the colour and rotation will always be at index 0 and 1 respectively.

Other than that nothing spectacular happened for the first part.

My vector rotation function uses a simplified version of the two dimensional rotation matrix which means it rotates counterclockwise. But I treated it as though it rotated clockwise at first. This wouldn’t have posed a problem for the first part, but the bug would’ve manifested had I used it for the second part, because the x axis would’ve been mirrored.

Speaking of mirrored, I used a coordinate system where the y axis is up but the puzzle seems to be treating y as down. The result was that my output was upside down, but that wasn’t a hard fix. It boils down to just printing the lines in reverse.

It’s a pity we don’t get to see each rendered character, otherwise I could implement the OCR I talked about in the post from day 8. I could look up other people’s solutions to cobble together an alphabet, but that’s a lot of work and I really like the way the coloured output looks. I will remember it for the next time though ;)

tags: intcode - drawing
Overview
Previous day Next day