Skip to content

Commit b415719

Browse files
committed
Fix problem by adding more lookback
1 parent e949ce9 commit b415719

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

2024/src/aoc/days/day24.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,30 @@ def find_invalid(output: str, pattern) -> set[str]:
8484

8585
return least_wrong
8686

87+
assert max_bit >= 3
88+
8789
# First one is a half adder, that's a simple pattern
8890
invalid = find_invalid("z00", ["XOR", "x00", "y00"])
8991
# Second one is missing a reference to the before-previous adder, so it's a
9092
# slightly different patterns
9193
invalid |= find_invalid(
9294
"z01", ["XOR", ["AND", "x00", "y00"], ["XOR", "x01", "y01"]]
9395
)
96+
# Needed a second lookback to determine that `ktp` is valid
97+
invalid |= find_invalid(
98+
"z02",
99+
[
100+
"XOR",
101+
["XOR", "x02", "y02"],
102+
[
103+
"OR",
104+
["AND", "x01", "y01"],
105+
["AND", ["XOR", "x01", "y01"], ["AND", "x00", "y00"]],
106+
],
107+
],
108+
)
94109

95-
for n in range(2, max_bit):
110+
for n in range(3, max_bit):
96111
xcurr = f"x{n:02}"
97112
ycurr = f"y{n:02}"
98113
zcurr = f"z{n:02}"
@@ -104,7 +119,11 @@ def find_invalid(output: str, pattern) -> set[str]:
104119
[
105120
"XOR",
106121
["XOR", xcurr, ycurr],
107-
["OR", ["AND", xprev, yprev], ["AND", ["XOR", xprev, yprev], None]],
122+
[
123+
"OR",
124+
["AND", xprev, yprev],
125+
["AND", ["XOR", xprev, yprev], ["OR", None, None]],
126+
],
108127
],
109128
)
110129

0 commit comments

Comments
 (0)