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

part1 (3327B)


      1--- Day 9: Sensor Boost ---
      2
      3You've just said goodbye to the rebooted rover and left Mars when you receive a faint distress
      4signal coming from the asteroid belt.  It must be the Ceres monitoring station!
      5
      6In order to lock on to the signal, you'll need to boost your sensors. The Elves send up the latest
      7BOOST program - Basic Operation Of System Test.
      8
      9While BOOST (your puzzle input) is capable of boosting your sensors, for tenuous safety reasons, it
     10refuses to do so until the computer it runs on passes some checks to demonstrate it is a
     11complete Intcode computer.
     12
     13Your existing Intcode computer is missing one key feature: it needs support for parameters in
     14relative mode.
     15
     16Parameters in mode 2, relative mode, behave very similarly to parameters in position mode: the
     17parameter is interpreted as a position.  Like position mode, parameters in relative mode can be read
     18from or written to.
     19
     20The important difference is that relative mode parameters don't count from address 0.  Instead, they
     21count from a value called the relative base. The relative base starts at 0.
     22
     23The address a relative mode parameter refers to is itself plus the current relative base. When the
     24relative base is 0, relative mode parameters and position mode parameters with the same value refer
     25to the same address.
     26
     27For example, given a relative base of 50, a relative mode parameter of -7 refers to memory address
     2850 + -7 = 43.
     29
     30The relative base is modified with the relative base offset instruction:
     31
     32
     33 - Opcode 9 adjusts the relative base by the value of its only parameter. The relative base
     34increases (or decreases, if the value is negative) by the value of the parameter.
     35
     36
     37For example, if the relative base is 2000, then after the instruction 109,19, the relative base
     38would be 2019. If the next instruction were 204,-34, then the value at address 1985 would be output.
     39
     40Your Intcode computer will also need a few other capabilities:
     41
     42
     43 - The computer's available memory should be much larger than the initial program. Memory beyond the
     44initial program starts with the value 0 and can be read or written like any other memory. (It is
     45invalid to try to access memory at a negative address, though.)
     46
     47 - The computer should have support for large numbers. Some instructions near the beginning of the
     48BOOST program will verify this capability.
     49
     50
     51Here are some example programs that use these features:
     52
     53
     54 - 109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99 takes no input and produces a copy of
     55itself as output.
     56
     57 - 1102,34915192,34915192,7,4,7,99,0 should output a 16-digit number.
     58
     59 - 104,1125899906842624,99 should output the large number in the middle.
     60
     61
     62The BOOST program will ask for a single input; run it in test mode by providing it the value 1. It
     63will perform a series of checks on each opcode, output any opcodes (and the associated parameter
     64modes) that seem to be functioning incorrectly, and finally output a BOOST keycode.
     65
     66Once your Intcode computer is fully functional, the BOOST program should report no malfunctioning
     67opcodes when run in test mode; it should only output a single value, the BOOST keycode.
     68What BOOST keycode does it produce?
     69
     70