@@ -161,3 +161,37 @@ transformations. I think it's pretty readable and easy to understand what's happ
161
161
162
162
I'm running out of steam, so when I get around to it, I'm going to cheat for days 17 and 24 and see how someone
163
163
else solved them. Implementation is still helpful for learning!
164
+
165
+ ### 1/14/2025
166
+
167
+ Warning: spoilers for day 24 part 2 below.
168
+
169
+ I read some reddit posts to help me solve this one. Many of them suggested visualizing the graph of wires
170
+ to better grasp what's happening, so I output a [ graphviz] ( https://graphviz.org/ ) dot file and stared at it for a
171
+ while.
172
+
173
+ It gave me the idea to build a list of dependencies of the incorrect z wires, and filter out any wires that contributed
174
+ to correct z wires: this would reduce the swap candidates to just a handful of wires that I could viably test by trying
175
+ every possible combination of 4 swaps. This was misguided, however, since a "correct" z wire is dependent on the inputs,
176
+ and the solution has to work with ANY values in the x and y wires. Even using randomized x and y values to figure out
177
+ likely dependents eliminated too many candidates.
178
+
179
+ So I gave up solving it on my own, and dove more deeply into the reddit discussions. Most of them focus on
180
+ understanding the [ "full adder"] ( https://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder ) : the puzzle input
181
+ basically constructs one of these (except for the 4 swapped gates, of course). Interestingly, many people solved this
182
+ puzzle without code: they did it using pen and paper, and/or by inspecting a visual graph by eye and noticing how it
183
+ "obviously" deviated from the composition of gates for a full adder. But this wasn't obvious to me. I could see the
184
+ general shape of the graph and the places where it seemed off, but beyond that, it gave me a headache to try to
185
+ identify what the configuration of the full adder should look like for each z wire.
186
+
187
+ I ended up implementing [ a solution by someone] ( https://www.reddit.com/r/adventofcode/comments/1hneuf0/comment/m41ms44/ )
188
+ who used a brute force approach I thought was pretty clever: set up a bunch of test devices with randomized x and y
189
+ values, find a swap that results in the most improvement for all of them, and repeat until you find the set of 4 swaps
190
+ that works for every test device. After adding caching to the evaluation of wire values, my solution ran in only 35s
191
+ (the author reported it taking 2.5 mins on their machine). More details are in the code.
192
+
193
+ I suppose slogging through it was worth the insight into how mathematical addition works at the level of logical gates
194
+ (you need a carry bit!), even if I didn't use that knowledge for the actual solution.
195
+
196
+ Anyway, day 17 part 2 is the last remaining puzzle for me. Like day 24, it involves implementing a computer. Ugh,
197
+ I dislike these types of problems so much.
0 commit comments