Skip to content

Commit 6e997ad

Browse files
committed
[Day 25] Add solution
1 parent 64dde16 commit 6e997ad

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This Julia package contains my solutions for [Advent of Code 2024](https://adven
3434
| 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) |
3535
| 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) |
3636
| 24 | [:white_check_mark:](https://adventofcode.com/2024/day/24) | 5.658 s | 3.28 GiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day24.jl) |
37-
<!-- | 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) | -->
37+
| 25 | [:white_check_mark:](https://adventofcode.com/2024/day/25) | 2.178 ms | 3.47 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day25.jl) |
3838

3939

4040
The benchmarks have been measured on this machine:

src/AdventOfCode2024.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module AdventOfCode2024
33
using BenchmarkTools
44
using Printf
55

6-
solvedDays = 1:24
6+
solvedDays = 1:25
77
# Include the source files:
88
for day in solvedDays
99
ds = @sprintf("%02d", day)

src/day25.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Day25
2+
3+
using AdventOfCode2024
4+
5+
6+
function day25(input::String = readInput(joinpath(@__DIR__, "..", "data", "day25.txt")))
7+
locks, keys = parse_input(input)
8+
total = 0
9+
for lock locks
10+
for key keys
11+
if all(lock .+ key .<= 5)
12+
total += 1
13+
end
14+
end
15+
end
16+
return total
17+
end
18+
19+
function parse_input(input)
20+
locks = NTuple{5,Int}[]
21+
keys = NTuple{5,Int}[]
22+
for elem eachsplit(input, "\n\n")
23+
data = map(x -> x[1], reduce(vcat, permutedims.(map(x -> split(x, ""), split(elem)))))
24+
if all(data[1, :] .== '#')
25+
v = Int[]
26+
for j axes(data, 2)
27+
i = 1
28+
while data[i,j] == '#'
29+
i += 1
30+
end
31+
push!(v, i - 2)
32+
end
33+
push!(locks, Tuple(v))
34+
elseif all(data[end, :] .== '#')
35+
v = Int[]
36+
for j axes(data, 2)
37+
i = size(data, 1)
38+
while data[i,j] == '#'
39+
i -= 1
40+
end
41+
push!(v, size(data, 1) - i - 1)
42+
end
43+
push!(keys, Tuple(v))
44+
end
45+
end
46+
return locks, keys
47+
end
48+
49+
end # module

test/runtests.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,48 @@ end
393393

394394
@testset "Day 24" begin
395395
@test AdventOfCode2024.Day24.day24() == [58367545758258, "bpf,fdw,hcc,hqc,qcw,z05,z11,z35"]
396+
end
397+
398+
@testset "Day 25" begin
399+
sample = "#####\n" *
400+
".####\n" *
401+
".####\n" *
402+
".####\n" *
403+
".#.#.\n" *
404+
".#...\n" *
405+
".....\n" *
406+
"\n" *
407+
"#####\n" *
408+
"##.##\n" *
409+
".#.##\n" *
410+
"...##\n" *
411+
"...#.\n" *
412+
"...#.\n" *
413+
".....\n" *
414+
"\n" *
415+
".....\n" *
416+
"#....\n" *
417+
"#....\n" *
418+
"#...#\n" *
419+
"#.#.#\n" *
420+
"#.###\n" *
421+
"#####\n" *
422+
"\n" *
423+
".....\n" *
424+
".....\n" *
425+
"#.#..\n" *
426+
"###..\n" *
427+
"###.#\n" *
428+
"###.#\n" *
429+
"#####\n" *
430+
"\n" *
431+
".....\n" *
432+
".....\n" *
433+
".....\n" *
434+
"#....\n" *
435+
"#.#..\n" *
436+
"#.#.#\n" *
437+
"#####\n"
438+
@test AdventOfCode2024.Day25.day25(sample) == 3
439+
@test AdventOfCode2024.Day25.day25() == 3291
396440
end

0 commit comments

Comments
 (0)