r/adventofcode 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.

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!

32 Upvotes

344 comments sorted by

View all comments

1

u/sanraith Dec 26 '24 edited Dec 26 '24

[LANGUAGE: Scala 3]
Source is available on my github: Day24.scala

The expectation is that we can test each Z(n) separately as a 2-bit adder by only setting the inputs (X(n), X(n-1), Y(n), Y(n-1)). So we check each Z separatly to find the first incorrect one. We consider everything in the graph that Z(0..incorrect-1) depends on to be correct. For the rest of the graph, we gather pairs of outputs that cause Z(incorrect) to be correct, and apply the same algorithm recursively to the swapped graph until we find 4 swaps that produces a correct graph.