add day 1 solution
This commit is contained in:
parent
65124706d6
commit
d2687a5602
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,21 @@
|
|||
import strutils
|
||||
|
||||
proc countIncreases(): uint =
|
||||
var
|
||||
line = ""
|
||||
prevDepth = high(uint)
|
||||
while readLine(stdin, line):
|
||||
if line.len() > 0:
|
||||
let depth = parseUint(line)
|
||||
if depth > prevDepth:
|
||||
result.inc()
|
||||
prevDepth = depth
|
||||
|
||||
proc main(): int =
|
||||
try:
|
||||
echo countIncreases()
|
||||
except ValueError:
|
||||
result = -1
|
||||
|
||||
when isMainModule:
|
||||
quit(main())
|
|
@ -0,0 +1,25 @@
|
|||
import algorithm
|
||||
import math
|
||||
import strutils
|
||||
|
||||
const WindowSize = 3
|
||||
|
||||
proc countIncreases(): uint =
|
||||
var
|
||||
line = ""
|
||||
window: array[WindowSize + 1, uint]
|
||||
while readLine(stdin, line):
|
||||
if line.len() > 0:
|
||||
window.rotateLeft(1)
|
||||
window[^1] = parseUint(line)
|
||||
if window[0] > 0 and sum(window[1 .. ^1]) > sum(window[0 .. ^2]):
|
||||
result.inc()
|
||||
|
||||
proc main(): int =
|
||||
try:
|
||||
echo countIncreases()
|
||||
except ValueError:
|
||||
result = -1
|
||||
|
||||
when isMainModule:
|
||||
quit(main())
|
|
@ -0,0 +1,10 @@
|
|||
199
|
||||
200
|
||||
208
|
||||
210
|
||||
200
|
||||
207
|
||||
240
|
||||
269
|
||||
260
|
||||
263
|
Loading…
Reference in New Issue