This commit is contained in:
Huanzo 2021-12-01 06:40:41 +01:00
parent ba2ae7d0cb
commit 44b07c2f8f

View File

@ -1,12 +1,29 @@
include(joinpath(readchomp(`git rev-parse --show-toplevel`), "aoc.jl")) include(joinpath(readchomp(`git rev-parse --show-toplevel`), "aoc.jl"))
import .Aoc: @aoc import .Aoc: @aoc
function p1(input) function sliding(in, w)
nothing ((@view in[i:i+w-1]) for i in 1:1:length(in)-w+1)
end end
function p2(input) function day1(in, w)
meassurements = parse.(Int, in)
prev = sum(meassurements[begin:begin+w-1])
c = 0
for i sliding(meassurements, w)
s = sum(i)
s > prev && (c += 1)
prev = s
end
c
end
function p1(input)
day1(input, 1)
end
function p2(input)
day1(input, 3)
end end
@aoc(2021, 1) @aoc(2021, 1)