AoC 2019 D5: Sunny with a Chance of Asteroids
| Problem statement | Source code | Tags: Intcode
← Previous Back to AoC Index Next →
The Intcode itself is relatively straightforward, but I spent some time ironing out the infrastructure for code sharing, especially since it's a bit tricky in C++.
At this point, my code is still functional. My intcode.hpp file contains two functions:
It modifies the codes vector in place, and returns a vector of outputs. The inputs are provided as a vector as well, and consumed in order.
- Input and output instructions are straightforward to implement. One reads from the input vector, and the other appends to the output vector.
- Parameter modes require changing
codes[op1]toeval_param(codes, inst.params[0])(ah yes, I also have astruct Instthat holds the opcode and parameters, each with mode/value, and a function to extract this information).eval_paramjust checks the mode and either returns the value at that position or the immediate value. - The main
forloop doesn't increment by a fixed amount anymore; instead, each instruction in theswitchstatement specifies the newivalue at the end. - The jump instructions just set
iinstead of incrementing it.
The new main loop looks like this: