diff options
Diffstat (limited to 'AoC2022/03/solver.jl')
-rw-r--r-- | AoC2022/03/solver.jl | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/AoC2022/03/solver.jl b/AoC2022/03/solver.jl index 13bb2a9..04d954b 100644 --- a/AoC2022/03/solver.jl +++ b/AoC2022/03/solver.jl @@ -5,11 +5,11 @@ data = open("input") do f end priority(x) = islowercase(x) ? x - 'a' + 1 : x - 'A' + 27 +s_halver(s) = s[1:length(s)÷2], s[length(s)÷2+1:end] + +solver(block) = (block .|> s-> intersect(s...)[1] .|> priority )|> sum @testset "solutions" begin - @test map( - s -> intersect(s[1:length(s)÷2], s[length(s)÷2+1:end])[1] |> priority, - data, - ) |> sum == 8072 - @test [intersect(data[i:i+2]...)[1] for i ∈ 1:3:length(data)] .|> priority |> sum == 2567 + @test data .|> s_halver |> solver == 8072 + @test [data[i:i+2] for i ∈ 1:3:length(data)] |> solver == 2567 end |