-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchallenge.nim
More file actions
28 lines (24 loc) · 742 Bytes
/
challenge.nim
File metadata and controls
28 lines (24 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import std/strutils
import std/sequtils
proc parseInput(instr: string): seq[int] =
result = instr.
splitLines.
toSeq.
filter(proc(x: string): bool = x != "").
map(parseInt)
proc countIncreases(data: seq[int]): int =
for i in 1..data.high:
if data[i] > data[i-1]:
result = result + 1
proc partOne*(instr: string): int =
let input = parseInput(instr)
return countIncreases(input)
proc partTwo*(instr: string): int =
let input = parseInput(instr)
var sums: seq[int]
for i in countup(0, len(input)-3):
sums.add(input[i] + input[i+1] + input[i+2])
# sums.add(
# (@input[i..i+2]).foldl(a+b),
# )
return countIncreases(sums)