Skip to content

Commit 73e97b4

Browse files
committed
[Day 24] Finalize solution
1 parent ba30908 commit 73e97b4

File tree

2 files changed

+4
-88
lines changed

2 files changed

+4
-88
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ This Julia package contains my solutions for [Advent of Code 2024](https://adven
3232
| 20 | [:white_check_mark:](https://adventofcode.com/2024/day/20) | 227.453 ms | 224.97 MiB| [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day20.jl) |
3333
| 22 | [:white_check_mark:](https://adventofcode.com/2024/day/22) | 241.724 ms | 78.80 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day22.jl) |
3434
| 23 | [:white_check_mark:](https://adventofcode.com/2024/day/23) | 4.197 ms | 3.82 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day23.jl) |
35+
| 24 | [:white_check_mark:](https://adventofcode.com/2024/day/24) | 9.476 s | 4.84 GiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day24.jl) |
3536
<!-- | 21 | [:white_check_mark:](https://adventofcode.com/2024/day/21) | 9.675 ms | 7.19 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day21.jl) | -->
36-
<!-- | 24 | [:white_check_mark:](https://adventofcode.com/2024/day/24) | 43.214 ms | 49.77 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day24.jl) | -->
3737
<!-- | 25 | [:white_check_mark:](https://adventofcode.com/2024/day/25) | 69.476 ms | 62.03 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day25.jl) | -->
3838

3939

src/day24.jl

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,23 @@ function day24(input::String = readInput(joinpath(@__DIR__, "..", "data", "day24
88

99
swapped_outputs = []
1010
_, wrong_adders = check_adders(rules, Int[])
11-
println("wrong_adders = $wrong_adders")
1211

1312
sequences = find_sequences(wrong_adders)
14-
1513
for sequence sequences
1614
nrules = needed_rules(rules, sequence)
17-
# ruleorder = nothing
1815
for collection (nrules, setdiff(1:length(rules), nrules))
1916
stop = false
2017
for ri collection
21-
println("ri = $ri")
2218
for rj nrules
2319
first, second = swap_outputs!(rules, ri , rj)
2420
corrects_critical_gates, ruleorder = check_adders_at_indices(rules, sequence)
2521
if corrects_critical_gates
26-
success, wrinds = check_adders(rules, sequence; ruleorder)
27-
if success && issubset(wrinds, wrong_adders)
28-
println("SUCCESS: $first, $second, (ri, rj) = ($ri, $rj), wrinds = $wrinds")
22+
success, _ = check_adders_at_indices(rules, setdiff(0:44, wrong_adders); ruleorder)
23+
if success
2924
push!(swapped_outputs, first)
3025
push!(swapped_outputs, second)
3126
stop = true
32-
wrong_adders = wrinds
27+
wrong_adders = setdiff(wrong_adders, sequence)
3328
break
3429
end
3530
end
@@ -96,85 +91,6 @@ function parse_input(input::AbstractString)
9691
return x, y, rule
9792
end
9893

99-
# function run(x::Int, y::Int, rules::Vector{NTuple{4, String}}; ruleorder::Vector{Int} = Int[])
100-
# state = Dict{String,Bool}()
101-
# unused_rules = Set(1:length(rules))
102-
# prev_length = length(unused_rules) + 1
103-
# reg = r"([xy])(\d{2})"
104-
# if isempty(ruleorder)
105-
# useruleorder = false
106-
# ruleorder = zeros(Int, length(rules))
107-
# elseif any(ruleorder .== 0)
108-
# return -1, ruleorder
109-
# else
110-
# useruleorder = true
111-
# end
112-
113-
# i = 1
114-
# while !isempty(unused_rules) && length(unused_rules) < prev_length
115-
# prev_length = length(unused_rules)
116-
117-
# if useruleorder
118-
# rulies = ruleorder
119-
# else
120-
# rulies = copy(unused_rules)
121-
# end
122-
# for ri ∈ rulies
123-
# rule = rules[ri]
124-
# values = [false, false]
125-
# found = false
126-
# for i ∈ 2:3
127-
# m = match(reg, rule[i])
128-
# if m !== nothing
129-
# found = true
130-
# index = parse(Int, m.captures[2])
131-
# if m.captures[1] == "x"
132-
# values[i-1] = (x >> index) % 2
133-
# else
134-
# values[i-1] = (y >> index) % 2
135-
# end
136-
# else
137-
# if haskey(state, rule[i])
138-
# found = true
139-
# values[i-1] = state[rule[i]]
140-
# else
141-
# found = false
142-
# break
143-
# end
144-
# end
145-
# end
146-
# if found
147-
# delete!(unused_rules, ri)
148-
# if i ∉ (1:222)
149-
# println(i)
150-
# end
151-
# ruleorder[i] = ri
152-
# i += 1
153-
# if rule[1] == "AND"
154-
# state[rule[4]] = values[1] & values[2]
155-
# elseif rule[1] == "OR"
156-
# state[rule[4]] = values[1] | values[2]
157-
# elseif rule[1] == "XOR"
158-
# state[rule[4]] = values[1] ⊻ values[2]
159-
# end
160-
# end
161-
# end
162-
# end
163-
164-
# !isempty(unused_rules) && return -1, ruleorder
165-
166-
# result = 0
167-
# i = 0
168-
# while true
169-
# id = _to_id(i, "z")
170-
# !haskey(state, id) && break
171-
# result += state[id] << i
172-
# i += 1
173-
# end
174-
# return result, ruleorder
175-
# end
176-
177-
17894
function run(x::Int, y::Int, rules::Vector{NTuple{4, String}}, ruleorder::Nothing)
17995
state = Dict{String,Bool}()
18096
unused_rules = Set(1:length(rules))

0 commit comments

Comments
 (0)