mirror of
https://github.com/daylinmorgan/advent-of-code-2023.git
synced 2024-12-21 19:10:43 -06:00
apply new setup to other solutions
This commit is contained in:
parent
8255ac49d2
commit
dcb3951fe1
6 changed files with 47 additions and 45 deletions
|
@ -1,5 +1,6 @@
|
||||||
import std/[algorithm,os,sequtils]
|
import std/[algorithm,os,sequtils]
|
||||||
|
|
||||||
task solve, "run all solutions":
|
task solve, "run all solutions":
|
||||||
for dir in walkDir("solutions").toSeq().sortedByIt(it.path):
|
for dir in walkDirRec("solutions", yieldFilter = {pcDir}).toSeq().sortedByIt(it):
|
||||||
selfExec "r --hint:all:off " & dir.path & "/solution.nim"
|
echo "--",dir,"--"
|
||||||
|
selfExec "r --hint:all:off " & dir & "/solution.nim"
|
||||||
|
|
|
@ -15,8 +15,6 @@ macro solve*(arg: untyped): untyped =
|
||||||
for stmt in arg:
|
for stmt in arg:
|
||||||
stmt.expectKind nnkCall
|
stmt.expectKind nnkCall
|
||||||
stmt[0].expectKind nnkIdent
|
stmt[0].expectKind nnkIdent
|
||||||
if not (stmt[0].eqIdent("example") or stmt[0].eqIdent("input")):
|
|
||||||
error "Invalid input identifier: " & stmt[0].strVal
|
|
||||||
stmt[1].expectKind nnkStmtList
|
stmt[1].expectKind nnkStmtList
|
||||||
for inputs in stmt[1]:
|
for inputs in stmt[1]:
|
||||||
inputs.expectKind nnkCall
|
inputs.expectKind nnkCall
|
||||||
|
@ -28,9 +26,11 @@ macro solve*(arg: untyped): untyped =
|
||||||
output = inputs[1][0]
|
output = inputs[1][0]
|
||||||
msg = newLit(part.repr & "|" & puzzleInput.repr)
|
msg = newLit(part.repr & "|" & puzzleInput.repr)
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
let color =
|
let solution = `part`(`puzzleInput`)
|
||||||
if `part`(`puzzleInput`) == `output`: fgGreen
|
if solution == `output`:
|
||||||
else: fgRed
|
stdout.styledWriteLine(fgGreen, `msg`, fgDefault)
|
||||||
stdout.styledWriteLine(color, `msg`, fgDefault, ": ", $`output`)
|
else:
|
||||||
|
stdout.styledWriteLine(fgRed, `msg`, fgDefault)
|
||||||
|
stdout.writeLine(" expected: ", $`output`, "; got: ", solution)
|
||||||
|
|
||||||
loadInputs()
|
loadInputs()
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import std/[strutils]
|
import std/[strutils]
|
||||||
|
|
||||||
const example* = slurp("example.txt").strip()
|
import ../aoc
|
||||||
const example2* = slurp("example2.txt").strip()
|
|
||||||
const input* = slurp("input.txt").strip()
|
|
||||||
|
|
||||||
proc parseInput(input: string): seq[string] =
|
proc parseInput(input: string): seq[string] =
|
||||||
input.split("\n")
|
input.split("\n")
|
||||||
|
@ -45,12 +43,23 @@ proc partTwo*(input: string): int =
|
||||||
inc i
|
inc i
|
||||||
result += parseInt(digits[0] & digits[^1])
|
result += parseInt(digits[0] & digits[^1])
|
||||||
|
|
||||||
when isMainModule:
|
const example2 = slurp("example2.txt").strip()
|
||||||
import std/unittest
|
|
||||||
suite "day 1":
|
solve:
|
||||||
test "part one":
|
example:
|
||||||
check partOne(example) == 142
|
partOne: 142
|
||||||
check partOne(input) == 54597
|
example2:
|
||||||
test "part two":
|
partTwo: 281
|
||||||
check partTwo(example2) == 281
|
input:
|
||||||
check partTwo(input) == 54504
|
partOne: 54597
|
||||||
|
partTwo: 54504
|
||||||
|
|
||||||
|
# when isMainModule:
|
||||||
|
# import std/unittest
|
||||||
|
# suite "day 1":
|
||||||
|
# test "part one":
|
||||||
|
# check partOne(example) == 142
|
||||||
|
# check partOne(input) == 54597
|
||||||
|
# test "part two":
|
||||||
|
# check partTwo(example2) == 281
|
||||||
|
# check partTwo(input) == 54504
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import std/[strutils, strscans]
|
import std/[strutils, strscans]
|
||||||
|
|
||||||
const example* = slurp("example.txt").strip()
|
import ../aoc
|
||||||
const input* = slurp("input.txt").strip()
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Color {.pure.} = enum
|
Color {.pure.} = enum
|
||||||
|
@ -47,13 +46,10 @@ proc partTwo*(input: string): int =
|
||||||
mins[col] = max(mins[col], cnt)
|
mins[col] = max(mins[col], cnt)
|
||||||
result += mins[red] * mins[green] * mins[blue]
|
result += mins[red] * mins[green] * mins[blue]
|
||||||
|
|
||||||
|
solve:
|
||||||
when isMainModule:
|
example:
|
||||||
import std/unittest
|
partOne: 8
|
||||||
suite "day 2":
|
partTwo: 2286
|
||||||
test "part one":
|
input:
|
||||||
check partOne(example) == 8
|
partOne: 2239
|
||||||
check partOne(input) == 2239
|
partTwo: 83435
|
||||||
test "part two":
|
|
||||||
check partTwo(example) == 2286
|
|
||||||
check partTwo(input) == 83435
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import std/[strutils, sequtils, sets, tables]
|
import std/[strutils, sequtils, sets, tables]
|
||||||
|
|
||||||
const example* = slurp("example.txt").strip()
|
import ../aoc
|
||||||
const input* = slurp("input.txt").strip()
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Pos = tuple[x, y: int]
|
Pos = tuple[x, y: int]
|
||||||
|
@ -76,13 +75,10 @@ proc partTwo*(input: string): int =
|
||||||
if parts.len == 2:
|
if parts.len == 2:
|
||||||
result += parts[0].val * parts[1].val
|
result += parts[0].val * parts[1].val
|
||||||
|
|
||||||
when isMainModule:
|
solve:
|
||||||
import std/unittest
|
example:
|
||||||
|
partOne: 4361
|
||||||
suite "day 3":
|
partTwo: 467835
|
||||||
test "part one":
|
input:
|
||||||
check partOne(example) == 4361
|
partOne: 536202
|
||||||
check partOne(input) == 536202
|
partTwo: 78272573
|
||||||
test "part two":
|
|
||||||
check partTwo(example) == 467835
|
|
||||||
check partTwo(input) == 78272573
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import std/[math, sets, sequtils, strutils, macros]
|
import std/[math, sets, sequtils, strutils]
|
||||||
|
|
||||||
import ../aoc
|
import ../aoc
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue