@@ -4,10 +4,10 @@ using AdventOfCode2024
44
55function day24(input:: String = readInput(joinpath(@__DIR__, " .." , " data" , " day24.txt" )))
66 x, y, rules = parse_input(input)
7- p1, _ = run(x, y, rules, nothing )
7+ p1, ruleorder = run(x, y, rules, nothing )
88
99 swapped_outputs = []
10- _, wrong_adders = check_adders (rules, Int[])
10+ wrong_adders = [i for i ∈ 0 : 44 if ! check_adders_at_indices (rules, [i]; ruleorder)[ 1 ]]
1111
1212 sequences = find_sequences(wrong_adders)
1313 for sequence ∈ sequences
@@ -91,7 +91,7 @@ function parse_input(input::AbstractString)
9191 return x, y, rule
9292end
9393
94- function run(x:: Int , y:: Int , rules:: Vector{NTuple{4, String}} , ruleorder :: Nothing )
94+ function run(x:: Int , y:: Int , rules:: Vector{NTuple{4, String}} , _ :: Nothing )
9595 state = Dict{String,Bool}()
9696 unused_rules = Set(1 : length(rules))
9797 prev_length = length(unused_rules) + 1
@@ -196,8 +196,6 @@ function run(x::Int, y::Int, rules::Vector{NTuple{4, String}}, ruleorder::Vector
196196 return result, ruleorder
197197end
198198
199-
200-
201199function needed_rules(rules:: Vector{NTuple{4, String}} , outinds:: Vector{Int} )
202200 ruleinds = Set{Int}()
203201 reg = r" [xy]\d {2}"
@@ -216,27 +214,6 @@ function needed_rules(rules::Vector{NTuple{4, String}}, outinds::Vector{Int})
216214 return ruleinds
217215end
218216
219- function check_adders(rules:: Vector{NTuple{4, String}} , ignore_indices:: Vector{Int} ; ruleorder:: Union{Vector{Int},Nothing} = nothing )
220- wrong = Int[]
221- xi = (0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 )
222- yi = (0 , 1 , 0 , 1 , 0 , 0 , 1 , 1 )
223- cprev = (0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 )
224- for index ∈ setdiff(0 : 44 , ignore_indices)
225- iter = index == 0 ? (1 : 4 ) : (1 : 8 )
226- for i ∈ iter
227- x = (xi[i] << index) + (cprev[i] << (index - 1 ))
228- y = (yi[i] << index) + (cprev[i] << (index - 1 ))
229- result, ruleorder = run(x, y, rules, ruleorder)
230- result == - 1 && return false , wrong
231- if result != x + y
232- push!(wrong, index)
233- break
234- end
235- end
236- end
237- return true , wrong
238- end
239-
240217function check_adders_at_indices(rules:: Vector{NTuple{4, String}} , indices:: Vector{Int} ; ruleorder:: Union{Vector{Int},Nothing} = nothing )
241218 xi = (0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 )
242219 yi = (0 , 1 , 0 , 1 , 0 , 0 , 1 , 1 )
0 commit comments