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

subinterval(a0, a1, b0, b1) = a0 <= b0 && a1 >= b1
subcontained(a0, a1, b0, b1) = subinterval(a0, a1, b0, b1) || subinterval(b0, b1, a0, a1)
overlap(a0, a1, b0, b1) = a0 <= b1 && b0 <= a1

data = open("input") do f
    map(l -> parse.(Int, l), eachsplit.(eachsplit(read(f, String)), r"[,-]"))
end

@testset "solutions" begin
    @test map(l -> subcontained(l...), data) |> sum == 515
    @test map(l -> overlap(l...), data) |> sum == 883
end