rvnash
Advent of Code 2024 - Day 24
Anyone have a solution to Part 2 today? Part 1 was straight forward, but I can’t figure out a programatic way to do part 2. I understand the properly constructed machine would be a carry-forward adder, so besides visualizing the configuration and looking for mis-wirings I’m not sure how to approach it.
Most Liked
Kevo
I think this is closer to the approach I was trying to figure out. Thanks for posting this. It does produce the correct result for my input. I am going to need to spend a bit more time on this to understand it fully and know for sure it’s doing what I think it is.
This is one aspect of elixir code that I haven’t really gotten comfortable with. For basic things the code seems so elegant and straightforward, but once things get complicated I seem to get lost and have a harder time visualizing what is actually getting passed between the functions. I’ve mostly done OOP stuff before and didn’t really experience this before. Maybe it’s more to do with the nature of Advent of Code than elixir in general. IDK
I would love a tool that could show visually what the parameters look like when you mouse over functions. I think that would be super cool and help a lot in these cases.
lud
I plan to do that too tomorrow. Wires should be present at two different places in the graph, as input and output for well known “xyz” names so building a mapping should be possible.
At least I hope ![]()
liamcmitchell
I think that’s how I’ve solved it.
Part 1 example (2.8ms): 2024
Part 1 input (5.0ms): 56620966442854
Part 2 input (96.2ms): "chv,jpj,kgj,rts,vvw,z07,z12,z26"
I make graphs of logic and input wires only, no intermediate names. This lets you easily test if a node is logically equal. I look up the intermediate names from a map when needed.
bjorng
I found the answer for my input just a few minutes ago, but I don’t have any code to share yet. (Too messy and it doesn’t solve the complete problem.)
What I did was to programmatically check for mis-wirings for each output (starting with z0). For my input, the first mis-wiring was for z18. Going from that to which wires to swap was not obvious, so I tried to figure it out by manually looking at how the gates were wired. I did a topological sort of the gates, which made it easier to try to understand what was happening.
I managed to figure out which two wires that were likely to fix the problems with z18, and tested that with my program. It fixed the problem and my checker gave me the next incorrect output. I quickly figured out two more pairs.
The final pair had a different kind of mis-wiring, which was harder to figure out manually. At that point I just added a brute-force search, testing swap each possible pair of wires. It finished in a few seconds.
I now think I now how this can be solved programmatically without any need for manual intervention. It might be a couple of days before I’ll have time to try that.
bjorng
It turns out that it is viable to do a brute-force search for one pair at the time. My solution finishes in about 8 seconds. I will share my code when I’ve cleaned it up.







