From b82253d66333170442545710b82d4953249a7afd Mon Sep 17 00:00:00 2001 From: Alexander Seiler Date: Sat, 13 Jan 2024 03:41:40 +0100 Subject: [PATCH] [Day 25] Improve performance --- README.md | 2 +- src/day25.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6740dd3..baad355 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ This Julia package contains my solutions for [Advent of Code 2023](https://adven | 22 | [:white_check_mark:](https://adventofcode.com/2023/day/22) | 790.712 ms | 631.26 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day22.jl) | | 23 | [:white_check_mark:](https://adventofcode.com/2023/day/23) | 2.979 s | 9.69 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day23.jl) | | 24 | [:white_check_mark:](https://adventofcode.com/2023/day/24) | 41.181 ms | 49.71 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day24.jl) | -| 25 | [:white_check_mark:](https://adventofcode.com/2023/day/25) | 153.698 ms | 176.55 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day25.jl) | +| 25 | [:white_check_mark:](https://adventofcode.com/2023/day/25) | 69.476 ms | 62.03 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day25.jl) | The benchmarks have been measured on this machine: diff --git a/src/day25.jl b/src/day25.jl index 4d486b1..495daaa 100644 --- a/src/day25.jl +++ b/src/day25.jl @@ -13,7 +13,7 @@ end function parse_input(input::AbstractString) i = 1 translations = Dict{String,Int}() - graph = Dict{Int, Set{Int}}() + graph = Dict{Int, Vector{Int}}() for line ∈ eachsplit(rstrip(input), "\n") nodes = split.(replace(line, ":" => ""), " ") n = Int[] @@ -22,7 +22,7 @@ function parse_input(input::AbstractString) push!(n, translations[node]) else translations[node] = i - graph[i] = Set{Int}() + graph[i] = Vector{Int}() push!(n, i) i += 1 end @@ -36,8 +36,8 @@ function parse_input(input::AbstractString) return graph, i - 1 end -function solve(graph::Dict{Int,Set{Int}}, total_size::Int) - for k = 1:total_size +function solve(graph::Dict{Int,Vector{Int}}, total_size::Int) + for k = shuffle(1:total_size) not_connected = PriorityQueue{Int,Int}() connected = Set{Int}() for i ∈ 1:total_size