AoC 2019 D11: Space Police

C++ | Problem statement | Source code | Tags: IntcodeManual inspection

← Previous Back to AoC Index Next →

The only additional capability from day 7 is that instead of having one number output at a time, the program now produces two outputs before pausing. Since the size is fixed, I just call run_until_output() twice to get both outputs.

Both parts work the same way. I keep track of the robot's position and direction, and a map of painted panels. Each time, I use send_input() to provide the current panel color, then call run_until_output() to get the new color and direction. Abstractly:

int x = 0, y = 0;
int dir_x = 0, dir_y = -1;
while (!prog.halted) {
prog.send_input(panels.find({x, y}) != panels.end() ? panels[{x, y}] : 0);
prog.run_until_output();
if (prog.halted) break;
panels[{x, y}] = prog.pop_output();
prog.run_until_output();
int turn = prog.pop_output();
// Update direction
}
cpp

Again, I take a second to admire the ASCII art in part 2:

 ###   ##  #  # ###  #    ###  #  # #  #
# # # # # # # # # # # # # # #
# # # ## # # # # # # # ##
### # # # ### # ### # # # #
# # # # # # # # # # # # #
# ## # # # # #### # ## # #

← Previous Back to AoC Index Next →