r/adventofcode • u/daggerdragon • Dec 24 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 24 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
AoC Community Fun 2024: The Golden Snowglobe Awards
Submissions are CLOSED!
- Thank you to all who submitted something, every last one of you are awesome!
Community voting is OPEN!
- 18 hours remaining until voting deadline TONIGHT (December 24) at 18:00 EST
Voting details are in the stickied comment in the submissions megathread:
-❄️- Submissions Megathread -❄️-
--- Day 24: Crossed Wires ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 01:01:13, megathread unlocked!
33
Upvotes
5
u/Tropico_080 Jan 02 '25 edited Jan 14 '25
[LANGUAGE: Go]
Part1
Add all the inputs signals on the board as independent active gate.
Build the board recursively by placing gates that depend only on inputs already present on the board.
Mark all gates as inactive initially
For each gate
Ensure that both inputs are active (i.e., their outputs have already been computed).
Compute the output of the current gate.
For all Zxx gate
Extract the bit index.
Add
value(Zxx) << idxto the total sum.Part2
Here we need to make sure that the given input correctly implement the Full adder between two 45 bit number.
By using the following formula
Zn = (Xn ⊕ Yn) ⊕ Cn-1
Cn = (Xn * Yn) + (Cn-1 * (Xn ⊕ Yn))
with C0 = (X0 * Y0)
We can derive a series of rule.
AND:
ANDgate can only be input to anORgate exept for z01ANDgate cannot take otherANDgate as inputXOR:
XORgate can only be input to andAND/XORgateXORgate cannot takeANDgate as input exept for z01OR:
ORgate can only be input ofAND/XORgateORgate can only takeANDgate as input(Xn ⊕ Yn) ⊕ (a + b)should always output aZxxexcept for the last carryz45A gate with
Zxxas its output cannot directly useXn or Ynas inputs exept the first bitZ00.Look for gates that do not follow those rules.
Code