Skip to content

Commit 72d21d0

Browse files
Prepare day 24
1 parent 488a855 commit 72d21d0

File tree

4 files changed

+497
-0
lines changed

4 files changed

+497
-0
lines changed

2024/Day_24/README.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
Link: <https://adventofcode.com/2024/day/24> <br>
2+
Author: Eric Wastl ([@ericwastl](https://twitter.com/ericwastl)) (2024)
3+
4+
---
5+
6+
## --- Day 24: Crossed Wires ---
7+
8+
You and The Historians arrive at the edge of a [large grove](/2022/day/23) somewhere in the jungle. After the last incident, the Elves installed a small device that monitors the fruit. While The Historians search the grove, one of them asks if you can take a look at the monitoring device; apparently, it's been malfunctioning recently.
9+
10+
The device seems to be trying to produce a number through some boolean logic gates. Each gate has two inputs and one output. The gates all operate on values that are either **true** (`1`) or **false** (`0`).
11+
12+
- `AND` gates output `1` if **both** inputs are `1`; if either input is `0`, these gates output `0`.
13+
- `OR` gates output `1` if **one or both** inputs is `1`; if both inputs are `0`, these gates output `0`.
14+
- `XOR` gates output `1` if the inputs are **different**; if the inputs are the same, these gates output `0`.
15+
16+
Gates wait until both inputs are received before producing output; wires can carry `0`, `1` or no value at all. There are no loops; once a gate has determined its output, the output will not change until the whole system is reset. Each wire is connected to at most one gate output, but can be connected to many gate inputs.
17+
18+
Rather than risk getting shocked while tinkering with the live system, you write down all of the gate connections and initial wire values (your puzzle input) so you can consider them in relative safety. For example:
19+
20+
```
21+
x00: 1
22+
x01: 1
23+
x02: 1
24+
y00: 0
25+
y01: 1
26+
y02: 0
27+
28+
x00 AND y00 -> z00
29+
x01 XOR y01 -> z01
30+
x02 OR y02 -> z02
31+
```
32+
33+
Because gates wait for input, some wires need to start with a value (as inputs to the entire system). The first section specifies these values. For example, `x00: 1` means that the wire named `x00` starts with the value `1` (as if a gate is already outputting that value onto that wire).
34+
35+
The second section lists all of the gates and the wires connected to them. For example, `x00 AND y00 -> z00` describes an instance of an `AND` gate which has wires `x00` and `y00` connected to its inputs and which will write its output to wire `z00`.
36+
37+
In this example, simulating these gates eventually causes `0` to appear on wire `z00`, `0` to appear on wire `z01`, and `1` to appear on wire `z02`.
38+
39+
Ultimately, the system is trying to produce a **number** by combining the bits on all wires starting with `z`. `z00` is the least significant bit, then `z01`, then `z02`, and so on.
40+
41+
In this example, the three output bits form the binary number `100` which is equal to the decimal number **`4`**.
42+
43+
Here's a larger example:
44+
45+
```
46+
x00: 1
47+
x01: 0
48+
x02: 1
49+
x03: 1
50+
x04: 0
51+
y00: 1
52+
y01: 1
53+
y02: 1
54+
y03: 1
55+
y04: 1
56+
57+
ntg XOR fgs -> mjb
58+
y02 OR x01 -> tnw
59+
kwq OR kpj -> z05
60+
x00 OR x03 -> fst
61+
tgd XOR rvg -> z01
62+
vdt OR tnw -> bfw
63+
bfw AND frj -> z10
64+
ffh OR nrd -> bqk
65+
y00 AND y03 -> djm
66+
y03 OR y00 -> psh
67+
bqk OR frj -> z08
68+
tnw OR fst -> frj
69+
gnj AND tgd -> z11
70+
bfw XOR mjb -> z00
71+
x03 OR x00 -> vdt
72+
gnj AND wpb -> z02
73+
x04 AND y00 -> kjc
74+
djm OR pbm -> qhw
75+
nrd AND vdt -> hwm
76+
kjc AND fst -> rvg
77+
y04 OR y02 -> fgs
78+
y01 AND x02 -> pbm
79+
ntg OR kjc -> kwq
80+
psh XOR fgs -> tgd
81+
qhw XOR tgd -> z09
82+
pbm OR djm -> kpj
83+
x03 XOR y03 -> ffh
84+
x00 XOR y04 -> ntg
85+
bfw OR bqk -> z06
86+
nrd XOR fgs -> wpb
87+
frj XOR qhw -> z04
88+
bqk OR frj -> z07
89+
y03 OR x01 -> nrd
90+
hwm AND bqk -> z03
91+
tgd XOR rvg -> z12
92+
tnw OR pbm -> gnj
93+
```
94+
95+
After waiting for values on all wires starting with `z`, the wires in this system have the following values:
96+
97+
```
98+
bfw: 1
99+
bqk: 1
100+
djm: 1
101+
ffh: 0
102+
fgs: 1
103+
frj: 1
104+
fst: 1
105+
gnj: 1
106+
hwm: 1
107+
kjc: 0
108+
kpj: 1
109+
kwq: 0
110+
mjb: 1
111+
nrd: 1
112+
ntg: 0
113+
pbm: 1
114+
psh: 1
115+
qhw: 1
116+
rvg: 0
117+
tgd: 0
118+
tnw: 1
119+
vdt: 1
120+
wpb: 0
121+
z00: 0
122+
z01: 0
123+
z02: 0
124+
z03: 1
125+
z04: 0
126+
z05: 1
127+
z06: 1
128+
z07: 1
129+
z08: 1
130+
z09: 1
131+
z10: 1
132+
z11: 0
133+
z12: 0
134+
```
135+
136+
Combining the bits from all wires starting with `z` produces the binary number `0011111101000`. Converting this number to decimal produces **`2024`**.
137+
138+
Simulate the system of gates and wires. **What decimal number does it output on the wires starting with `z`?**

0 commit comments

Comments
 (0)