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 (2652B)


      1--- Part Two ---
      2
      3"Good, the new computer seems to be working correctly!  Keep it nearby during this mission - you'll
      4probably use it again. Real Intcode computers support many more features than your new one, but
      5we'll let you know what they are as you need them."
      6
      7"However, your current priority should be to complete your gravity assist around the Moon. For this
      8mission to succeed, we should settle on some terminology for the parts you've already built."
      9
     10Intcode programs are given as a list of integers; these values are used as the initial state for the
     11computer's memory. When you run an Intcode program, make sure to start by initializing memory to the
     12program's values. A position in memory is called an address (for example, the first value in memory
     13is at "address 0").
     14
     15Opcodes (like 1, 2, or 99) mark the beginning of an instruction.  The values used immediately after
     16an opcode, if any, are called the instruction's parameters.  For example, in the instruction
     171,2,3,4, 1 is the opcode; 2, 3, and 4 are the parameters. The instruction 99 contains only an opcode
     18and has no parameters.
     19
     20The address of the current instruction is called the instruction pointer; it starts at 0.  After an
     21instruction finishes, the instruction pointer increases by the number of values in the
     22instruction; until you add more instructions to the computer, this is always 4 (1 opcode + 3
     23parameters) for the add and multiply instructions. (The halt instruction would increase the
     24instruction pointer by 1, but it halts the program instead.)
     25
     26"With terminology out of the way, we're ready to proceed. To complete the gravity assist, you need
     27to determine what pair of inputs produces the output 19690720."
     28
     29The inputs should still be provided to the program by replacing the values at addresses 1 and 2,
     30just like before.  In this program, the value placed in address 1 is called the noun, and the value
     31placed in address 2 is called the verb.   Each of the two input values will be between 0 and 99,
     32inclusive.
     33
     34Once the program has halted, its output is available at address 0, also just like before. Each time
     35you try a pair of inputs, make sure you first reset the computer's memory to the values in the
     36program (your puzzle input) - in other words, don't reuse memory from a previous attempt.
     37
     38Find the input noun and verb that cause the program to produce the output 19690720. What is 100 *
     39noun + verb? (For example, if noun=12 and verb=2, the answer would be 1202.)
     40
     41