Rename day1

This commit is contained in:
Joey Yakimowich-Payne 2021-12-03 20:17:54 -07:00
commit c257ed1410
4 changed files with 0 additions and 0 deletions

38
day1/p2.nim Normal file
View file

@ -0,0 +1,38 @@
import os
import sequtils
import std/strutils
proc main() =
let fileName = paramStr(1)
var increased = 0
var lastVal = -1
var window = [0, 0, 0]
var windowPos = 0
for val in fileName.lines:
let intVal = val.parseInt
var curVal = 0
window[windowPos] = intVal
if windowPos == (len(window) - 1):
# add the values and store
curVal = window.foldl(a + b)
if lastVal != -1 and lastVal < curVal:
increased += 1
lastVal = curVal
# move values up the window
window[0] = window[1]
window[1] = window[2]
window[2] = intVal
else:
windowPos += 1
echo increased, " increases"
main()