Advent of Code 2019 Day 9
Try the simulator with your puzzle input!
Task: Solve for X where...
X = the BOOST keycode
X = the coordinates of the distress signal
Several example inputs
109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99 1102,34915192,34915192,7,4,7,99,0 104,1125899906842624,99
Each one represents:
- An Intcode program that runs on a Intcode computer
- Where each integer represents either an opcode, a parameter mode, or a parameter within a larger instruction
- Intcode computer: Round 4!
test modeto troubleshoot my computer
Intcode computer: Round 4!
Previous articles in this series - for Days 2, 5 and 7 - summarize the rules learned up to those points.
Up to now, my Intcode computer understands the following rules:
- Parameters modes
This puzzle introduces:
- One new bit of state to manage:
relative base, which starts at
- One new opcode:
9- this modifies the
- One new parameter mode:
2- this looks-up the proper value in memory in relation to the
- Values stored in memory will be orders of magnitude larger than previously encountered
- Memory addresses referenced throughout the program that exist beyond the initial maximum addresses allocated - the program must be updated to accommodate and look-up or write to these locations without error mid-execution of the program
test mode to troubleshoot my computer
As noted in the instructions:
The BOOST program will ask for a single input; run it in test mode by providing it the value 1. It will perform a series of checks on each opcode, output any opcodes (and the associated parameter modes) that seem to be functioning incorrectly, and finally output a BOOST keycode.
Once your Intcode computer is fully functional, the BOOST program should report no malfunctioning opcodes when run in test mode; it should only output a single value, the BOOST keycode.
After adding code to accommodate the new rules, I ran my program with input
I saw this output:
I knew this meant there was a bug in my Intcode computer's logic.
As added help, I was logging out each opcode-parameter combination encountered during the program up to the point where it halts.
Here's what I saw near that output:
209 209 203
Prior to the first
209, no logged integers contained a
2 in any parameter position.
What was this trying to tell me?
- I likely wasn't handling
relative modecorrectly in my instruction functions for opcodes
When inspecting those functions' code, I noticed something I overlooked from Day 5's rules:
Parameters that an instruction writes to will never be in immediate mode.
I over-accounted for this by hard-coding
position mode a.k.a.
0 in functions that write to a value.
As a fix, I adjusted all instances of that to always refer to the parameter mode used just-in-time.
I re-ran the program.
My output only included one value:
- A 10-digit integer
It was the correct answer!
The easiest Part 2 ever:
Run the program with input 2 Wait a little while Return the single output value, a coordinate
It was the correct answer again!
I did it!!
As celebrated at the beginning of Part 2's instructions:
I now have a complete Intcode computer.
- I solved both parts!
- I've now solved eight parts of four puzzles wherein I successfully built an Intcode computer
- I've built four simulators that re-enact certain features of an Intcode computer
- I've completed 4/5 puzzles referenced in Day 25 - fingers crossed that I'm able to solve Day 17's puzzle, too!
Top comments (0)