aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-19 22:45:20 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-19 22:45:20 +0800
commitad940fa52f8bc45f07b5678eee4d94ee662e769b (patch)
tree38cb5bb6414ebed16832398fe8ac7d061d2f8af4 /src
parent7da1f98aaad6260d68ca0a819f0f7c5388b47a4d (diff)
downloadadvent-of-code-ad940fa52f8bc45f07b5678eee4d94ee662e769b.tar.gz
advent-of-code-ad940fa52f8bc45f07b5678eee4d94ee662e769b.zip
2018 2019 day7 part1
Diffstat (limited to 'src')
-rw-r--r--src/2018/day7/README.md30
-rw-r--r--src/2019/day7/README.md33
-rw-r--r--src/2019/day7/aoc.cpp1
3 files changed, 64 insertions, 0 deletions
diff --git a/src/2018/day7/README.md b/src/2018/day7/README.md
index b41f421..7cc28f6 100644
--- a/src/2018/day7/README.md
+++ b/src/2018/day7/README.md
@@ -35,4 +35,34 @@ So, in this example, the correct order is CABDFE.
In what order should the steps in your instructions be completed?
+--- Part Two ---
+As you're about to begin construction, four of the Elves offer to help. "The sun will set soon; it'll go faster if we work together." Now, you need to account for multiple people working on steps simultaneously. If multiple steps are available, workers should still begin them in alphabetical order.
+Each step takes 60 seconds plus an amount corresponding to its letter: A=1, B=2, C=3, and so on. So, step A takes 60+1=61 seconds, while step Z takes 60+26=86 seconds. No time is required between steps.
+
+To simplify things for the example, however, suppose you only have help from one Elf (a total of two workers) and that each step takes 60 fewer seconds (so that step A takes 1 second and step Z takes 26 seconds). Then, using the same instructions as above, this is how each second would be spent:
+
+Second Worker 1 Worker 2 Done
+ 0 C .
+ 1 C .
+ 2 C .
+ 3 A F C
+ 4 B F CA
+ 5 B F CA
+ 6 D F CAB
+ 7 D F CAB
+ 8 D F CAB
+ 9 D . CABF
+ 10 E . CABFD
+ 11 E . CABFD
+ 12 E . CABFD
+ 13 E . CABFD
+ 14 E . CABFD
+ 15 . . CABFDE
+Each row represents one second of time. The Second column identifies how many seconds have passed as of the beginning of that second. Each worker column shows the step that worker is currently doing (or . if they are idle). The Done column shows completed steps.
+
+Note that the order of the steps has changed; this is because steps now take time to finish and multiple workers can begin multiple steps simultaneously.
+
+In this example, it would take 15 seconds for two workers to complete these steps.
+
+With 5 workers and the 60+ second step durations described above, how long will it take to complete all of the steps?
diff --git a/src/2019/day7/README.md b/src/2019/day7/README.md
index 3e5a2e3..d61902d 100644
--- a/src/2019/day7/README.md
+++ b/src/2019/day7/README.md
@@ -38,3 +38,36 @@ Max thruster signal 65210 (from phase setting sequence 1,0,4,3,2):
1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0
Try every combination of phase settings on the amplifiers. What is the highest signal that can be sent to the thrusters?
+--- Part Two ---
+It's no good - in this configuration, the amplifiers can't generate a large enough output signal to produce the thrust you'll need. The Elves quickly talk you through rewiring the amplifiers into a feedback loop:
+
+ O-------O O-------O O-------O O-------O O-------O
+0 -+->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-.
+ | O-------O O-------O O-------O O-------O O-------O |
+ | |
+ '--------------------------------------------------------+
+ |
+ v
+ (to thrusters)
+Most of the amplifiers are connected as they were before; amplifier A's output is connected to amplifier B's input, and so on. However, the output from amplifier E is now connected into amplifier A's input. This creates the feedback loop: the signal will be sent through the amplifiers many times.
+
+In feedback loop mode, the amplifiers need totally different phase settings: integers from 5 to 9, again each used exactly once. These settings will cause the Amplifier Controller Software to repeatedly take input and produce output many times before halting. Provide each amplifier its phase setting at its first input instruction; all further input/output instructions are for signals.
+
+Don't restart the Amplifier Controller Software on any amplifier during this process. Each one should continue receiving and sending signals until it halts.
+
+All signals sent or received in this process will be between pairs of amplifiers except the very first signal and the very last signal. To start the process, a 0 signal is sent to amplifier A's input exactly once.
+
+Eventually, the software on the amplifiers will halt after they have processed the final loop. When this happens, the last output signal from amplifier E is sent to the thrusters. Your job is to find the largest output signal that can be sent to the thrusters using the new phase settings and feedback loop arrangement.
+
+Here are some example programs:
+
+Max thruster signal 139629729 (from phase setting sequence 9,8,7,6,5):
+
+3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,
+27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5
+Max thruster signal 18216 (from phase setting sequence 9,7,8,5,6):
+
+3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,
+-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,
+53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10
+Try every combination of the new phase settings on the amplifier feedback loop. What is the highest signal that can be sent to the thrusters?
diff --git a/src/2019/day7/aoc.cpp b/src/2019/day7/aoc.cpp
index c1a8ba5..176683a 100644
--- a/src/2019/day7/aoc.cpp
+++ b/src/2019/day7/aoc.cpp
@@ -8,6 +8,7 @@ void find_max(int* is, int i, std::set<int>& ns, int* max, const std::vector<int
if (i == 10) {
set_computer(&is[i - 2]);
int n = run_computer(codes);
+ // printf("%d %d %d %d %d -> %d\n", is[0], is[2], is[4], is[6], is[8], n);
if (n > *max) {
*max = n;
}