advent-of-code/2021/one.nim

16 lines
543 B
Nim
Raw Normal View History

import ./common
2021-12-01 16:41:27 -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
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
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