Forget this - not doing it tonight
This commit is contained in:
parent
da61289cbb
commit
56aa6595fc
|
@ -31,7 +31,7 @@ template time*(i: string, body: untyped): untyped =
|
||||||
body
|
body
|
||||||
let stop = cpuTime()
|
let stop = cpuTime()
|
||||||
let diff = $((stop - start) * 1000)
|
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):
|
when not defined(release):
|
||||||
echo "NOTE: This is not a real measurement of performance. Compile in release mode with -d:release for best performance."
|
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}"
|
# jkp: {(stop - start) * 1000} ms to calculate solution: {result}"
|
||||||
|
|
12
2021/eight.nim
Normal file
12
2021/eight.nim
Normal 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)
|
18
2021/one.nim
18
2021/one.nim
|
@ -1,15 +1,9 @@
|
||||||
import ./common
|
import ./common, std/[sequtils, sugar]
|
||||||
|
|
||||||
proc countDepthIncreases(inputs: seq[int], dist=1): int =
|
proc countDepthIncreases(inputs: seq[int], dist=1): int =
|
||||||
for i in dist..<inputs.len():
|
(dist..<inputs.len()).toSeq().foldl(a + int(inputs[b] > inputs[b-dist]), 0)
|
||||||
if inputs[i] > inputs[i-dist]: inc result
|
|
||||||
|
|
||||||
let input = 1.loadInput().toInts()
|
doDay(1, (n) => n.loadInput().toInts(),
|
||||||
time("countDepthIncreases part 1"): echo input.countDepthIncreases()
|
(n) => n.countDepthIncreases(),
|
||||||
time("countDepthIncreases part 2"): echo input.countDepthIncreases(3)
|
(n) => n.countDepthIncreases(3),
|
||||||
|
@[199,200,208,210,200,207,240,269,260,263], 7, 5)
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in a new issue