aoc-2019-c

Advent of Code 2019 Solutions in C
git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

part2 (3493B)


      1--- Part Two ---
      2
      3The air conditioner comes online! Its cold air feels good for a while, but then the TEST alarms
      4start to go off. Since the air conditioner can't vent its heat anywhere but back into the
      5spacecraft, it's actually making the air inside the ship warmer.
      6
      7Instead, you'll need to use the TEST to extend the thermal radiators. Fortunately, the diagnostic
      8program (your puzzle input) is already equipped for this.  Unfortunately, your Intcode computer is
      9not.
     10
     11Your computer is only missing a few opcodes:
     12
     13
     14 - Opcode 5 is jump-if-true: if the first parameter is non-zero, it sets the instruction pointer to
     15the value from the second parameter. Otherwise, it does nothing.
     16
     17 - Opcode 6 is jump-if-false: if the first parameter is zero, it sets the instruction pointer to the
     18value from the second parameter. Otherwise, it does nothing.
     19
     20 - Opcode 7 is less than: if the first parameter is less than the second parameter, it stores 1 in
     21the position given by the third parameter.  Otherwise, it stores 0.
     22
     23 - Opcode 8 is equals: if the first parameter is equal to the second parameter, it stores 1 in the
     24position given by the third parameter.  Otherwise, it stores 0.
     25
     26
     27Like all instructions, these instructions need to support parameter modes as described above.
     28
     29Normally, after an instruction is finished, the instruction pointer increases by the number of
     30values in that instruction. However, if the instruction modifies the instruction pointer, that value
     31is used and the instruction pointer is not automatically increased.
     32
     33For example, here are several programs that take one input, compare it to the value 8, and then
     34produce one output:
     35
     36
     37 - 3,9,8,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is equal to 8; output
     381 (if it is) or 0 (if it is not).
     39
     40 - 3,9,7,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is less than 8; output
     411 (if it is) or 0 (if it is not).
     42
     43 - 3,3,1108,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is equal to 8; output 1
     44(if it is) or 0 (if it is not).
     45
     46 - 3,3,1107,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is less than 8; output
     471 (if it is) or 0 (if it is not).
     48
     49
     50Here are some jump tests that take an input, then output 0 if the input was zero or 1 if the input
     51was non-zero:
     52
     53
     54 - 3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9 (using position mode)
     55
     56 - 3,3,1105,-1,9,1101,0,0,12,4,12,99,1 (using immediate mode)
     57
     58
     59Here's a larger example:
     60
     613,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,
     621106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,
     63999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99
     64
     65The above example program uses an input instruction to ask for a single number.  The program will
     66then output 999 if the input value is below 8, output 1000 if the input value is equal to 8, or
     67output 1001 if the input value is greater than 8.
     68
     69This time, when the TEST diagnostic program runs its input instruction to get the ID of the system
     70to test, provide it 5, the ID for the ship's thermal radiator controller. This diagnostic test suite
     71only outputs one number, the diagnostic code.
     72
     73What is the diagnostic code for system ID 5?
     74
     75