From 3032a7ef81a28bff0f3d8cae9ec3e8ff7ead186e Mon Sep 17 00:00:00 2001 From: Danny Harpigny Date: Wed, 5 Jan 2022 09:09:10 +0100 Subject: [PATCH] --- 2021/01/first.nim | 10 ++++++---- 2021/01/second.nim | 10 ++++++---- 2021/02/both.nim | 8 +++++--- 2021/03/first.nim | 10 ++++++---- 2021/03/second.nim | 10 ++++++---- 2021/04/first.nim | 14 +++++++------- 2021/04/second.nim | 14 +++++++------- 2021/05/both.nim | 18 ++++++++++-------- 2021/06/both.nim | 16 +++++++++------- 2021/07/first.nim | 12 +++++++----- 2021/07/second.nim | 16 +++++++++------- 2021/08/first.nim | 14 ++++++++------ 2021/09/first.nim | 14 ++++++++------ adventofcode.nim | 8 ++++---- 14 files changed, 98 insertions(+), 76 deletions(-) diff --git a/2021/01/first.nim b/2021/01/first.nim index c7c1a2c..9d32be4 100644 --- a/2021/01/first.nim +++ b/2021/01/first.nim @@ -1,8 +1,10 @@ import - ../../adventofcode, - sequtils, - strformat, - strutils + std/sequtils, + std/strformat, + std/strutils + +import + ../../adventofcode let input = adventofcode.getInput(2021, 1) let lines = input.splitLines().mapIt(it.parseInt()) diff --git a/2021/01/second.nim b/2021/01/second.nim index a126609..283edd4 100644 --- a/2021/01/second.nim +++ b/2021/01/second.nim @@ -1,8 +1,10 @@ import - ../../adventofcode, - sequtils, - strformat, - strutils + std/sequtils, + std/strformat, + std/strutils + +import + ../../adventofcode let input = adventofcode.getInput(2021, 1) let lines = input.splitLines().mapIt(it.parseInt()) diff --git a/2021/02/both.nim b/2021/02/both.nim index 162cc59..bf992e4 100644 --- a/2021/02/both.nim +++ b/2021/02/both.nim @@ -1,7 +1,9 @@ import - ../../adventofcode, - strutils, - strformat + std/strformat, + std/strutils + +import + ../../adventofcode let input = adventofcode.getInput(2021, 2) let lines = input.splitLines() diff --git a/2021/03/first.nim b/2021/03/first.nim index 55a44ef..c58fd99 100644 --- a/2021/03/first.nim +++ b/2021/03/first.nim @@ -1,8 +1,10 @@ import - ../../adventofcode, - sequtils, - strutils, - strformat + std/sequtils, + std/strformat, + std/strutils + +import + ../../adventofcode let input = adventofcode.getInput(2021, 3) let lines = input.splitLines() diff --git a/2021/03/second.nim b/2021/03/second.nim index c7e6307..9831c59 100644 --- a/2021/03/second.nim +++ b/2021/03/second.nim @@ -1,8 +1,10 @@ import - ../../adventofcode, - sequtils, - strutils, - strformat + std/sequtils, + std/strformat, + std/strutils + +import + ../../adventofcode let input = adventofcode.getInput(2021, 3) let lines = input.splitLines() diff --git a/2021/04/first.nim b/2021/04/first.nim index 2fb0e57..43b8f95 100644 --- a/2021/04/first.nim +++ b/2021/04/first.nim @@ -1,12 +1,12 @@ +import + std/math, + std/sequtils, + std/strformat, + std/strutils + import ../../adventofcode, - math, - sequtils, - strutils, - strformat - -import - x/board + ./x/board let input = adventofcode.getInput(2021, 4) let lines = input.splitLines() diff --git a/2021/04/second.nim b/2021/04/second.nim index bb62919..14ea942 100644 --- a/2021/04/second.nim +++ b/2021/04/second.nim @@ -1,12 +1,12 @@ +import + std/math, + std/sequtils, + std/strformat, + std/strutils + import ../../adventofcode, - math, - sequtils, - strutils, - strformat - -import - x/board + ./x/board let input = adventofcode.getInput(2021, 4) let lines = input.splitLines() diff --git a/2021/05/both.nim b/2021/05/both.nim index dcb27d1..6953558 100644 --- a/2021/05/both.nim +++ b/2021/05/both.nim @@ -1,10 +1,12 @@ import - ../../adventofcode, - hashes, - sequtils, - strutils, - strformat, - tables + std/hashes, + std/sequtils, + std/strformat, + std/strutils, + std/tables + +import + ../../adventofcode type Grid = TableRef[Point, int] @@ -22,10 +24,10 @@ B = b >= 0 ? 2 * b : -2 * b - 1; A >= B ? A * A + A + B : A + B * B; ]# proc hash(p: Point): Hash = - let A = + let A = block: if p.x >= 0: 2 * p.x else: -2 * p.x - 1 - let B = + let B = block: if p.y >= 0: 2 * p.y else: -2 * p.y - 1 return diff --git a/2021/06/both.nim b/2021/06/both.nim index 9484426..d6cfd28 100644 --- a/2021/06/both.nim +++ b/2021/06/both.nim @@ -1,10 +1,12 @@ import - ../../adventofcode, - math, - sequtils, - strutils, - strformat, - tables + std/math, + std/sequtils, + std/strformat, + std/strutils, + std/tables + +import + ../../adventofcode type Cycle = int @@ -43,7 +45,7 @@ proc newDay() = fishes[cycle] += temporaryBox[cycle] when isMainModule: - const simulateDays = + const simulateDays = block: when defined(second): 256 else: 80 diff --git a/2021/07/first.nim b/2021/07/first.nim index 6c68e29..e2cd69b 100644 --- a/2021/07/first.nim +++ b/2021/07/first.nim @@ -1,9 +1,11 @@ import - ../../adventofcode, - options, - sequtils, - strformat, - strutils + std/options, + std/sequtils, + std/strformat, + std/strutils + +import + ../../adventofcode let input = adventofcode.getInput(2021, 7)[0 .. ^2] #let input = "16,1,2,0,4,2,7,1,2,14" # Example given diff --git a/2021/07/second.nim b/2021/07/second.nim index fc73956..fe3dd26 100644 --- a/2021/07/second.nim +++ b/2021/07/second.nim @@ -1,15 +1,17 @@ import - ../../adventofcode, - math, - sequtils, - strformat, - strutils - + std/math, + std/sequtils, + std/strformat, + std/strutils + +import + ../../adventofcode + let input = adventofcode.getInput(2021, 7) #let input = "16,1,2,0,4,2,7,1,2,14" # Example given let crabs = input.split(",").mapIt(it.parseInt()) -let avg = toInt math.floor((math.sum crabs) / crabs.len()) +let avg = (math.sum crabs) div crabs.len() var fuel = 0 for crab in crabs: diff --git a/2021/08/first.nim b/2021/08/first.nim index 52a9cf4..b9fc6c5 100644 --- a/2021/08/first.nim +++ b/2021/08/first.nim @@ -1,10 +1,12 @@ import - ../../adventofcode, - math, - sequtils, - strformat, - strutils, - tables + std/math, + std/sequtils, + std/strformat, + std/strutils, + std/tables + +import + ../../adventofcode let lines = adventofcode.getInput(2021, 8).splitLines() var decodedDigits = newTable[int, int]() diff --git a/2021/09/first.nim b/2021/09/first.nim index 28e4ad7..41e9a0f 100644 --- a/2021/09/first.nim +++ b/2021/09/first.nim @@ -1,10 +1,12 @@ import - ../../adventofcode, - math, - options, - sequtils, - strformat, - strutils + std/math, + std/options, + std/sequtils, + std/strformat, + std/strutils + +import + ../../adventofcode type Grid = seq[seq[int]] diff --git a/adventofcode.nim b/adventofcode.nim index 5e1f462..2a21ffe 100644 --- a/adventofcode.nim +++ b/adventofcode.nim @@ -1,8 +1,8 @@ import - httpclient, - os, - strformat, - strutils + std/httpclient, + std/os, + std/strformat, + std/strutils proc getInput*(year, day: int): string = try: