aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/03/solver.jl
blob: 04d954b3f4901fb27b1402ed5f93b2db124e24ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using Test

data = open("input") do f
    split(read(f, String))
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 data .|> s_halver |> solver == 8072
    @test [data[i:i+2] for i  1:3:length(data)] |> solver == 2567
end