add solution for day 4

This commit is contained in:
Patrick Michl 2022-12-04 18:54:32 +01:00
parent 61b961dc12
commit 9eadc6a3c1
No known key found for this signature in database
GPG Key ID: BFE0ACEE21CD5EB0
3 changed files with 1018 additions and 1 deletions

1000
data/day_4.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,4 +12,3 @@ function p2(input::Vector{String})
end
@aoc(2022, 3)

18
src/day_4.jl Normal file
View File

@ -0,0 +1,18 @@
include(joinpath(readchomp(`git rev-parse --show-toplevel`), "aoc.jl"))
import .Aoc: @aoc
function assignment_pairs(λ, line)
a, b = split(line, ',')
s1,e1,s2,e2 = parse.(Int,[split(a, '-'); split(b, '-')])
λ(s1:e1, s2:e2)
end
function p1(input::Vector{String})
count(map((x) -> assignment_pairs((a, b) -> (a b || b a), x), input))
end
function p2(input::Vector{String})
count(map((x) -> assignment_pairs((a, b) -> length(intersect(a, b)) > 0, x), input))
end
@aoc(2022, 4)