-- CodingAP's Advent of Code Hub --

[Back to Hub]

Advent of Code 2024, Day 24

-- Crossed Wires --

Leaderboard Positions - Part 1: 1142, Part 2: 138

Video Replay

Hello all! In this puzzle, we are analyzing a 45-bit full adder that has some gates swapped. We are given an initial set of wires that start with x and y, and we are also given a set of gates that tell the output using intermediate wires and z wires. In part 1, we needed to simulate the gates until all z wires produced a result. This was similar to Day 7, 2015 where we did a similar puzzle. This involves waiting for all the wires to be executed, then parsing the binary number afterwards. In part 2, we are given the fact that this entire circuit is a full-adder with 45 bits, and some of the gates' output have been swapped. Exactly 4 pairs, or 8 wires, have been swapped, and we must analyze the gates to find the incorrect ones. Thankfully, we don't have to switch them ourselves, but just output them in an alphabetical list separated by commas. I first did it manually after trying to remember what the full-adder circuit looked like, but then I extracted these rules that helped me. First, here is a diagram of a full-adder:

       _____
X-+---|     \        _____
  |   | XOR  |-+----|     \
Y---+-|_____/  |    | XOR  |-------Z
  | |          |  +-|_____/
  | |  _____   |  |
  +---|     \  |  | 
    | | AND  |-|--|-----------+   _____
    +-|_____/  |  |  _____    +--|     \
               +--|-|     \      | OR   |------Cout
                  | | AND  |-----|_____/
                  |-|_____/
                  |
                  |
Cin---------------+

(look up a diagram if you can't read it, i made this for fun)

Using this, we can pull some rules out that we can then check for all x, y, and z wires. Here are the rules that worked for my input:

After checking for all these rules, I sent the incorrect ones to an array, and I found 8 that matched. Most of this was manual checks, I just did some automation to allow my work to be proved. This may not work for all cases.