aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/03
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-02-06 00:01:53 +0100
committerOscar Najera <hi@oscarnajera.com>2023-02-06 00:01:53 +0100
commit99bcf55e2df61cef89cb88213e6feddd88294d47 (patch)
tree4aba0a910a4b0f1f8819346f7fc9b9da06dc5999 /AoC2022/03
parent57e563bf8f4fae7364118619318b338f16792473 (diff)
downloadscratch-99bcf55e2df61cef89cb88213e6feddd88294d47.tar.gz
scratch-99bcf55e2df61cef89cb88213e6feddd88294d47.tar.bz2
scratch-99bcf55e2df61cef89cb88213e6feddd88294d47.zip
day 3 review
Diffstat (limited to 'AoC2022/03')
-rw-r--r--AoC2022/03/solver.jl10
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