add solution for day 4
This commit is contained in:
parent
61b961dc12
commit
9eadc6a3c1
1000
data/day_4.txt
Normal file
1000
data/day_4.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,4 +12,3 @@ function p2(input::Vector{String})
|
||||
end
|
||||
|
||||
@aoc(2022, 3)
|
||||
|
||||
|
18
src/day_4.jl
Normal file
18
src/day_4.jl
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user