Advent of Code 2019

The story of my slow descent into madness

View on GitHub
9 December 2019

Day 9: Sensor Boost

by Simon Berger


Links:

Hey, it’s back (yet again). I’m glad I didn’t extract the intcode interpreter for nothing.

I already praised this reoccurring theme enough, so let’s just skip ahead to other things.

Today’s puzzle adds a new parameter mode, an opcode to manipulate the way this mode works, and the requirement for INFINITE MEMORY.

To comply with the requirement of unlimited memory I added methods for accessing the memory. The getter method returns 0 if the index is out of bounds and the setter resizes the memory vector and fills the new slots with zeroes if necessary. This means that memory is only expanded when absolutely necessary, that is, when it is being written to.

Adding the parameter mode was as simple as adding a new arm to the mode matching arm and so was adding the new instruction.

An interesting issue (which was also the only issue) I encountered was that I never added support for parameter modes to the write target address (this didn’t pose a problem because there used to be only one valid mode). This means that all parameters representing addresses to write to were read in position mode; regardless of their actual mode. To solve this I added another new method which handles writing to a parameter’s address and actually handles the parameter mode.

Even though I didn’t use it (and I don’t think it’s all that helpful), I extended the debug mode a bit to display more details.

If you’re curious, running both parts of today’s puzzle only takes 300ms.

I timed the execution of cargo run -- input.txt . This time includes the overhead of running the code using cargo (unoptimized + debuginfo), reading and parsing the input, and constructing the interpreters.

I’m only mentioning this because the puzzle reads “[…] it might take a few seconds to complete the operation on slower hardware.” and I was afraid that I would have to optimise my solution. Thanks, Rust, for not making me do that!

And no, I didn’t forget about my “promise” to add a converter from intcode to a human readable format. I simply didn’t get to it today.

tags: intcode
Overview
Previous day Next day