This commit is contained in:
Danny Hpy 2022-01-05 09:09:10 +01:00
parent c0326ec08e
commit 3032a7ef81
Signed by: dannyhpy
GPG Key ID: 7139FBBEA22D1CEC
14 changed files with 98 additions and 76 deletions

View File

@ -1,8 +1,10 @@
import import
../../adventofcode, std/sequtils,
sequtils, std/strformat,
strformat, std/strutils
strutils
import
../../adventofcode
let input = adventofcode.getInput(2021, 1) let input = adventofcode.getInput(2021, 1)
let lines = input.splitLines().mapIt(it.parseInt()) let lines = input.splitLines().mapIt(it.parseInt())

View File

@ -1,8 +1,10 @@
import import
../../adventofcode, std/sequtils,
sequtils, std/strformat,
strformat, std/strutils
strutils
import
../../adventofcode
let input = adventofcode.getInput(2021, 1) let input = adventofcode.getInput(2021, 1)
let lines = input.splitLines().mapIt(it.parseInt()) let lines = input.splitLines().mapIt(it.parseInt())

View File

@ -1,7 +1,9 @@
import import
../../adventofcode, std/strformat,
strutils, std/strutils
strformat
import
../../adventofcode
let input = adventofcode.getInput(2021, 2) let input = adventofcode.getInput(2021, 2)
let lines = input.splitLines() let lines = input.splitLines()

View File

@ -1,8 +1,10 @@
import import
../../adventofcode, std/sequtils,
sequtils, std/strformat,
strutils, std/strutils
strformat
import
../../adventofcode
let input = adventofcode.getInput(2021, 3) let input = adventofcode.getInput(2021, 3)
let lines = input.splitLines() let lines = input.splitLines()

View File

@ -1,8 +1,10 @@
import import
../../adventofcode, std/sequtils,
sequtils, std/strformat,
strutils, std/strutils
strformat
import
../../adventofcode
let input = adventofcode.getInput(2021, 3) let input = adventofcode.getInput(2021, 3)
let lines = input.splitLines() let lines = input.splitLines()

View File

@ -1,12 +1,12 @@
import
std/math,
std/sequtils,
std/strformat,
std/strutils
import import
../../adventofcode, ../../adventofcode,
math, ./x/board
sequtils,
strutils,
strformat
import
x/board
let input = adventofcode.getInput(2021, 4) let input = adventofcode.getInput(2021, 4)
let lines = input.splitLines() let lines = input.splitLines()

View File

@ -1,12 +1,12 @@
import
std/math,
std/sequtils,
std/strformat,
std/strutils
import import
../../adventofcode, ../../adventofcode,
math, ./x/board
sequtils,
strutils,
strformat
import
x/board
let input = adventofcode.getInput(2021, 4) let input = adventofcode.getInput(2021, 4)
let lines = input.splitLines() let lines = input.splitLines()

View File

@ -1,10 +1,12 @@
import import
../../adventofcode, std/hashes,
hashes, std/sequtils,
sequtils, std/strformat,
strutils, std/strutils,
strformat, std/tables
tables
import
../../adventofcode
type type
Grid = TableRef[Point, int] 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; A >= B ? A * A + A + B : A + B * B;
]# ]#
proc hash(p: Point): Hash = proc hash(p: Point): Hash =
let A = let A = block:
if p.x >= 0: 2 * p.x if p.x >= 0: 2 * p.x
else: -2 * p.x - 1 else: -2 * p.x - 1
let B = let B = block:
if p.y >= 0: 2 * p.y if p.y >= 0: 2 * p.y
else: -2 * p.y - 1 else: -2 * p.y - 1
return return

View File

@ -1,10 +1,12 @@
import import
../../adventofcode, std/math,
math, std/sequtils,
sequtils, std/strformat,
strutils, std/strutils,
strformat, std/tables
tables
import
../../adventofcode
type type
Cycle = int Cycle = int
@ -43,7 +45,7 @@ proc newDay() =
fishes[cycle] += temporaryBox[cycle] fishes[cycle] += temporaryBox[cycle]
when isMainModule: when isMainModule:
const simulateDays = const simulateDays = block:
when defined(second): 256 when defined(second): 256
else: 80 else: 80

View File

@ -1,9 +1,11 @@
import import
../../adventofcode, std/options,
options, std/sequtils,
sequtils, std/strformat,
strformat, std/strutils
strutils
import
../../adventofcode
let input = adventofcode.getInput(2021, 7)[0 .. ^2] let input = adventofcode.getInput(2021, 7)[0 .. ^2]
#let input = "16,1,2,0,4,2,7,1,2,14" # Example given #let input = "16,1,2,0,4,2,7,1,2,14" # Example given

View File

@ -1,15 +1,17 @@
import import
../../adventofcode, std/math,
math, std/sequtils,
sequtils, std/strformat,
strformat, std/strutils
strutils
import
../../adventofcode
let input = adventofcode.getInput(2021, 7) let input = adventofcode.getInput(2021, 7)
#let input = "16,1,2,0,4,2,7,1,2,14" # Example given #let input = "16,1,2,0,4,2,7,1,2,14" # Example given
let crabs = input.split(",").mapIt(it.parseInt()) 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 var fuel = 0
for crab in crabs: for crab in crabs:

View File

@ -1,10 +1,12 @@
import import
../../adventofcode, std/math,
math, std/sequtils,
sequtils, std/strformat,
strformat, std/strutils,
strutils, std/tables
tables
import
../../adventofcode
let lines = adventofcode.getInput(2021, 8).splitLines() let lines = adventofcode.getInput(2021, 8).splitLines()
var decodedDigits = newTable[int, int]() var decodedDigits = newTable[int, int]()

View File

@ -1,10 +1,12 @@
import import
../../adventofcode, std/math,
math, std/options,
options, std/sequtils,
sequtils, std/strformat,
strformat, std/strutils
strutils
import
../../adventofcode
type type
Grid = seq[seq[int]] Grid = seq[seq[int]]

View File

@ -1,8 +1,8 @@
import import
httpclient, std/httpclient,
os, std/os,
strformat, std/strformat,
strutils std/strutils
proc getInput*(year, day: int): string = proc getInput*(year, day: int): string =
try: try: