diff options
author | Oscar Najera <hi@oscarnajera.com> | 2023-02-06 00:01:53 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2023-02-06 00:01:53 +0100 |
commit | 99bcf55e2df61cef89cb88213e6feddd88294d47 (patch) | |
tree | 4aba0a910a4b0f1f8819346f7fc9b9da06dc5999 /AoC2022/03 | |
parent | 57e563bf8f4fae7364118619318b338f16792473 (diff) | |
download | scratch-99bcf55e2df61cef89cb88213e6feddd88294d47.tar.gz scratch-99bcf55e2df61cef89cb88213e6feddd88294d47.tar.bz2 scratch-99bcf55e2df61cef89cb88213e6feddd88294d47.zip |
day 3 review
Diffstat (limited to 'AoC2022/03')
-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 |