2021-12-02 11:00:05 -06:00
|
|
|
import ./common
|
2021-12-01 16:41:27 -06:00
|
|
|
|
2021-12-02 11:00:05 -06:00
|
|
|
proc countDepthIncreases(inputs: seq[int], dist=1): int =
|
|
|
|
for i in dist..<inputs.len():
|
2021-12-01 16:41:27 -06:00
|
|
|
if inputs[i] > inputs[i-dist]: inc result
|
|
|
|
|
2021-12-02 11:00:05 -06:00
|
|
|
let input = 1.loadInput().toInts()
|
|
|
|
time("countDepthIncreases part 1"): echo input.countDepthIncreases()
|
|
|
|
time("countDepthIncreases part 2"): echo input.countDepthIncreases(3)
|
2021-12-01 16:41:27 -06:00
|
|
|
|
2021-12-02 11:00:05 -06:00
|
|
|
when not defined(release):
|
|
|
|
static:
|
|
|
|
let testInputs = @[199, 200, 208, 210, 200, 207, 240, 269, 260, 263]
|
|
|
|
doAssert testInputs.countDepthIncreases() == 7
|
|
|
|
doAssert testInputs.countDepthIncreases(3) == 5
|