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


      1--- Day 7: Amplification Circuit ---
      2
      3Based on the navigational maps, you're going to need to send more power to your ship's thrusters to
      4reach Santa in time. To do this, you'll need to configure a series of amplifiers already installed
      5on the ship.
      6
      7There are five amplifiers connected in series; each one receives an input signal and produces an
      8output signal.  They are connected such that the first amplifier's output leads to the second
      9amplifier's input, the second amplifier's output leads to the third amplifier's input, and so on. 
     10The first amplifier's input value is 0, and the last amplifier's output leads to your ship's
     11thrusters.
     12
     13    O-------O  O-------O  O-------O  O-------O  O-------O
     140 ->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-> (to thrusters)
     15    O-------O  O-------O  O-------O  O-------O  O-------O
     16
     17The Elves have sent you some Amplifier Controller Software (your puzzle input), a program that
     18should run on your existing Intcode computer. Each amplifier will need to run a copy of the program.
     19
     20When a copy of the program starts running on an amplifier, it will first use an input instruction to
     21ask the amplifier for its current phase setting (an integer from 0 to 4). Each phase setting is used
     22exactly once, but the Elves can't remember which amplifier needs which phase setting.
     23
     24The program will then call another input instruction to get the amplifier's input signal, compute
     25the correct output signal, and supply it back to the amplifier with an output instruction. (If the
     26amplifier has not yet received an input signal, it waits until one arrives.)
     27
     28Your job is to find the largest output signal that can be sent to the thrusters by trying every
     29possible combination of phase settings on the amplifiers. Make sure that memory is not shared or
     30reused between copies of the program.
     31
     32For example, suppose you want to try the phase setting sequence 3,1,2,4,0, which would mean setting
     33amplifier A to phase setting 3, amplifier B to setting 1, C to 2, D to 4, and E to 0. Then, you
     34could determine the output signal that gets sent from amplifier E to the thrusters with the
     35following steps:
     36
     37
     38 - Start the copy of the amplifier controller software that will run on amplifier A. At its first
     39input instruction, provide it the amplifier's phase setting, 3.  At its second input instruction,
     40provide it the input signal, 0.  After some calculations, it will use an output instruction to
     41indicate the amplifier's output signal.
     42
     43 - Start the software for amplifier B. Provide it the phase setting (1) and then whatever output
     44signal was produced from amplifier A. It will then produce a new output signal destined for
     45amplifier C.
     46
     47 - Start the software for amplifier C, provide the phase setting (2) and the value from amplifier B,
     48then collect its output signal.
     49
     50 - Run amplifier D's software, provide the phase setting (4) and input value, and collect its output
     51signal.
     52
     53 - Run amplifier E's software, provide the phase setting (0) and input value, and collect its output
     54signal.
     55
     56
     57The final output signal from amplifier E would be sent to the thrusters. However, this phase setting
     58sequence may not have been the best one; another sequence might have sent a higher signal to the
     59thrusters.
     60
     61Here are some example programs:
     62
     63
     64 - Max thruster signal 43210 (from phase setting sequence 4,3,2,1,0):
     653,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0
     66
     67 - Max thruster signal 54321 (from phase setting sequence 0,1,2,3,4):
     683,23,3,24,1002,24,10,24,1002,23,-1,23,
     69101,5,23,23,1,24,23,23,4,23,99,0,0
     70
     71 - Max thruster signal 65210 (from phase setting sequence 1,0,4,3,2):
     723,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33,
     731002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0
     74
     75
     76Try every combination of phase settings on the amplifiers.  What is the highest signal that can be
     77sent to the thrusters?
     78
     79