Forget this - not doing it tonight

This commit is contained in:
Daniel Flanagan 2021-12-07 23:05:47 -06:00
parent da61289cbb
commit 56aa6595fc
3 changed files with 19 additions and 13 deletions

View File

@ -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}"

12
2021/eight.nim Normal file
View File

@ -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)

View File

@ -1,15 +1,9 @@
import ./common
import ./common, std/[sequtils, sugar]
proc countDepthIncreases(inputs: seq[int], dist=1): int =
for i in dist..<inputs.len():
if inputs[i] > inputs[i-dist]: inc result
(dist..<inputs.len()).toSeq().foldl(a + int(inputs[b] > 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)