aoc-2018-python

Advent of Code 2018 Solutions in Python
git clone https://git.sinitax.com/sinitax/aoc-2018-python
Log | Files | Refs | README | sfeed.txt

part2 (2822B)


      1--- Part Two ---
      2
      3It's no good - in this configuration, the amplifiers can't generate a large enough output signal to
      4produce the thrust you'll need.  The Elves quickly talk you through rewiring the amplifiers into a
      5feedback loop:
      6
      7      O-------O  O-------O  O-------O  O-------O  O-------O
      80 -+->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-.
      9   |  O-------O  O-------O  O-------O  O-------O  O-------O |
     10   |                                                        |
     11   '--------------------------------------------------------+
     12                                                            |
     13                                                            v
     14                                                     (to thrusters)
     15
     16Most of the amplifiers are connected as they were before; amplifier A's output is connected to
     17amplifier B's input, and so on. However, the output from amplifier E is now connected into amplifier
     18A's input. This creates the feedback loop: the signal will be sent through the amplifiers
     19many times.
     20
     21In feedback loop mode, the amplifiers need totally different phase settings: integers from 5 to 9,
     22again each used exactly once. These settings will cause the Amplifier Controller Software to
     23repeatedly take input and produce output many times before halting. Provide each amplifier its phase
     24setting at its first input instruction; all further input/output instructions are for signals.
     25
     26Don't restart the Amplifier Controller Software on any amplifier during this process. Each one
     27should continue receiving and sending signals until it halts.
     28
     29All signals sent or received in this process will be between pairs of amplifiers except the very
     30first signal and the very last signal. To start the process, a 0 signal is sent to amplifier A's
     31input exactly once.
     32
     33Eventually, the software on the amplifiers will halt after they have processed the final loop. When
     34this happens, the last output signal from amplifier E is sent to the thrusters. Your job is to
     35find the largest output signal that can be sent to the thrusters using the new phase settings and
     36feedback loop arrangement.
     37
     38Here are some example programs:
     39
     40
     41 - Max thruster signal 139629729 (from phase setting sequence 9,8,7,6,5):
     423,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,
     4327,4,27,1001,28,-1,28,1005,28,6,99,0,0,5
     44
     45 - Max thruster signal 18216 (from phase setting sequence 9,7,8,5,6):
     463,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,
     47-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,
     4853,1001,56,-1,56,1005,56,6,99,0,0,0,0,10
     49
     50
     51Try every combination of the new phase settings on the amplifier feedback loop.  What is the highest
     52signal that can be sent to the thrusters?
     53
     54