| Problem statement | Source code | Tags: Intcode
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.
codes[op1] to eval_param(codes, inst.params[0]) (ah yes, I also have a struct Inst that holds the opcode and parameters, each with mode/value, and a function to extract this information). eval_param just checks the mode and either returns the value at that position or the immediate value.for loop doesn't increment by a fixed amount anymore; instead, each instruction in the switch statement specifies the new i value at the end.i instead of incrementing it.The new main loop looks like this: