2020-12-02 21:33:18 -06:00
|
|
|
import input_requestor, os, macros, strformat, tables
|
|
|
|
|
|
|
|
macro loadDays(): untyped =
|
|
|
|
var solver_str = "var solvers = {\n"
|
|
|
|
result = newStmtList()
|
2020-12-07 00:44:55 -06:00
|
|
|
for day in 1..25:
|
2020-12-02 21:33:18 -06:00
|
|
|
let module = fmt"day{day}"
|
|
|
|
if fileExists joinPath("src/", &"{module}.nim"):
|
|
|
|
result.add parseStmt fmt"from {module} import nil"
|
2020-12-03 10:13:34 -06:00
|
|
|
# TODO: do I "need" to close these streams?
|
2020-12-02 21:33:18 -06:00
|
|
|
solver_str = solver_str & &"""
|
2020-12-03 09:54:58 -06:00
|
|
|
{day}: proc(): tuple[part1: int, part2: int] =
|
2020-12-03 11:42:18 -06:00
|
|
|
stdout.write "Day {day}: "
|
2020-12-03 09:54:58 -06:00
|
|
|
(
|
|
|
|
{module}.part1(getInputFileStreamForDay({day})),
|
|
|
|
{module}.part2(getInputFileStreamForDay({day}))
|
|
|
|
),
|
2020-12-02 21:33:18 -06:00
|
|
|
"""
|
|
|
|
result.add parseStmt (solver_str & "\n}.newTable()\nexport solvers")
|
|
|
|
|
|
|
|
loadDays()
|