diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-04-07 17:18:18 -0400 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-04-07 17:19:39 -0400 |
| commit | 87ab487d59fa85dbe2afa55cc841b02805ae42ca (patch) | |
| tree | cd90ab715e1b5b5803674045dbafd6d51d27ac90 /src/05/part2 | |
| parent | 1bcc82c5bfbde87edd03c01ffdf9ee5934681592 (diff) | |
| download | aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.tar.gz aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.zip | |
Reorder days into src
Diffstat (limited to 'src/05/part2')
| -rw-r--r-- | src/05/part2 | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/05/part2 b/src/05/part2 new file mode 100644 index 0000000..fce9042 --- /dev/null +++ b/src/05/part2 @@ -0,0 +1,75 @@ +--- Part Two --- + +The air conditioner comes online! Its cold air feels good for a while, but then the TEST alarms +start to go off. Since the air conditioner can't vent its heat anywhere but back into the +spacecraft, it's actually making the air inside the ship [1m[97mwarmer[0m. + +Instead, you'll need to use the TEST to extend the thermal radiators. Fortunately, the diagnostic +program (your puzzle input) is already equipped for this. Unfortunately, your Intcode computer is +not. + +Your computer is only missing a few opcodes: + + + - Opcode 5 is [1m[97mjump-if-true[0m: if the first parameter is [1m[97mnon-zero[0m, it sets the instruction pointer to +the value from the second parameter. Otherwise, it does nothing. + + - Opcode 6 is [1m[97mjump-if-false[0m: if the first parameter [1m[97mis zero[0m, it sets the instruction pointer to the +value from the second parameter. Otherwise, it does nothing. + + - Opcode 7 is [1m[97mless than[0m: if the first parameter is [1m[97mless than[0m the second parameter, it stores 1 in +the position given by the third parameter. Otherwise, it stores 0. + + - Opcode 8 is [1m[97mequals[0m: if the first parameter is [1m[97mequal to[0m the second parameter, it stores 1 in the +position given by the third parameter. Otherwise, it stores 0. + + +Like all instructions, these instructions need to support [1m[97mparameter modes[0m as described above. + +Normally, after an instruction is finished, the instruction pointer increases by the number of +values in that instruction. [1m[97mHowever[0m, if the instruction modifies the instruction pointer, that value +is used and the instruction pointer is [1m[97mnot automatically increased[0m. + +For example, here are several programs that take one input, compare it to the value 8, and then +produce one output: + + + - 3,9,8,9,10,9,4,9,99,-1,8 - Using [1m[97mposition mode[0m, consider whether the input is [1m[97mequal to[0m 8; output +1 (if it is) or 0 (if it is not). + + - 3,9,7,9,10,9,4,9,99,-1,8 - Using [1m[97mposition mode[0m, consider whether the input is [1m[97mless than[0m 8; output +1 (if it is) or 0 (if it is not). + + - 3,3,1108,-1,8,3,4,3,99 - Using [1m[97mimmediate mode[0m, consider whether the input is [1m[97mequal to[0m 8; output 1 +(if it is) or 0 (if it is not). + + - 3,3,1107,-1,8,3,4,3,99 - Using [1m[97mimmediate mode[0m, consider whether the input is [1m[97mless than [0m8; output +1 (if it is) or 0 (if it is not). + + +Here are some jump tests that take an input, then output 0 if the input was zero or 1 if the input +was non-zero: + + + - 3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9 (using [1m[97mposition mode[0m) + + - 3,3,1105,-1,9,1101,0,0,12,4,12,99,1 (using [1m[97mimmediate mode[0m) + + +Here's a larger example: + +3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31, +1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104, +999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99 + +The above example program uses an input instruction to ask for a single number. The program will +then output 999 if the input value is below 8, output 1000 if the input value is equal to 8, or +output 1001 if the input value is greater than 8. + +This time, when the TEST diagnostic program runs its input instruction to get the ID of the system +to test, [1m[97mprovide it 5[0m, the ID for the ship's thermal radiator controller. This diagnostic test suite +only outputs one number, the [1m[97mdiagnostic code[0m. + +[1m[97mWhat is the diagnostic code for system ID 5?[0m + + |
