From 56aa6595fc973a2bbd3284a75daf2d9669a9a775 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 7 Dec 2021 23:05:47 -0600 Subject: [PATCH] Forget this - not doing it tonight --- 2021/common.nim | 2 +- 2021/eight.nim | 12 ++++++++++++ 2021/one.nim | 18 ++++++------------ 3 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 2021/eight.nim diff --git a/2021/common.nim b/2021/common.nim index 475a32d..4556fca 100644 --- a/2021/common.nim +++ b/2021/common.nim @@ -31,7 +31,7 @@ template time*(i: string, body: untyped): untyped = body let stop = cpuTime() let diff = $((stop - start) * 1000) - echo i & " took " & diff & "ms to calculate solution" + echo i & " took " & diff & "ms to process input file and calculate solution" when not defined(release): echo "NOTE: This is not a real measurement of performance. Compile in release mode with -d:release for best performance." # jkp: {(stop - start) * 1000} ms to calculate solution: {result}" diff --git a/2021/eight.nim b/2021/eight.nim new file mode 100644 index 0000000..d75884a --- /dev/null +++ b/2021/eight.nim @@ -0,0 +1,12 @@ +import ./common, std/[strutils, sequtils, strformat, sugar] + +proc p1(c: string): int = + result = 0 + +proc p2(c: string): int = + result = 0 + +doDay(8, (n) => n.loadInputText(), + p1, + p2, + "acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | cdfeb fcadb cdfeb cdbaf", 26, -1) diff --git a/2021/one.nim b/2021/one.nim index d82115d..6802916 100644 --- a/2021/one.nim +++ b/2021/one.nim @@ -1,15 +1,9 @@ -import ./common +import ./common, std/[sequtils, sugar] proc countDepthIncreases(inputs: seq[int], dist=1): int = - for i in dist.. inputs[i-dist]: inc result + (dist.. inputs[b-dist]), 0) -let input = 1.loadInput().toInts() -time("countDepthIncreases part 1"): echo input.countDepthIncreases() -time("countDepthIncreases part 2"): echo input.countDepthIncreases(3) - -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 +doDay(1, (n) => n.loadInput().toInts(), + (n) => n.countDepthIncreases(), + (n) => n.countDepthIncreases(3), + @[199,200,208,210,200,207,240,269,260,263], 7, 5)