From c551f3fad107ae0995de6096065bee9e6b9eafbb Mon Sep 17 00:00:00 2001 From: AKP Date: Thu, 2 Dec 2021 09:33:31 +0000 Subject: [PATCH] Tweak 2021-01 Nim solution --- .../2021/01-sonarSweep/nim/challenge.nim | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/challenges/2021/01-sonarSweep/nim/challenge.nim b/challenges/2021/01-sonarSweep/nim/challenge.nim index 1dd57b5..d922386 100644 --- a/challenges/2021/01-sonarSweep/nim/challenge.nim +++ b/challenges/2021/01-sonarSweep/nim/challenge.nim @@ -5,16 +5,22 @@ proc loadInput(): string = return readFile("input.txt") proc parseInput(instr: string): seq[int] = - for item in split(instr, "\n"): - if item == "": - continue - let n = parseInt(item) - result.add(n) + result = instr. + splitLines. + toSeq. + filter(proc(x: string): bool = x != ""). + map(parseInt) + + # for item in split(instr, "\n"): + # if item == "": + # continue + # let n = parseInt(item) + # result.add(n) let input = parseInput(loadInput()) proc countIncreases(data: seq[int]): int = - for i in countup(1, data.len()-1): + for i in 1..data.high: if data[i] > data[i-1]: result = result + 1