Ready for day 4

This commit is contained in:
Daniel Flanagan 2020-12-03 22:49:54 -06:00
parent 7419eccd05
commit 8ebbe45a29
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
5 changed files with 28 additions and 4 deletions

View file

@ -1,2 +1,17 @@
.PHONY: default run install build build-release build-tiny
default: run
run: run:
nimble run nimble run
build:
nimble build
build-release:
nimble build -d:release
build-tiny:
nimble build -d:release --opt:size
install:
nimble install

View file

@ -8,4 +8,5 @@ proc solve_for_day(n: int) {.used.} =
echo solvers[n]() echo solvers[n]()
when isMainModule: when isMainModule:
solve_all() # solve_all()
solve_for_day(4)

7
2020/src/day4.nim Normal file
View file

@ -0,0 +1,7 @@
import streams
proc part1*(s: Stream): int =
1
proc part2*(s: Stream): int =
2

View file

@ -3,7 +3,7 @@ import input_requestor, os, macros, strformat, tables
macro loadDays(): untyped = macro loadDays(): untyped =
var solver_str = "var solvers = {\n" var solver_str = "var solvers = {\n"
result = newStmtList() result = newStmtList()
for day in 1..3: for day in 1..4:
let module = fmt"day{day}" let module = fmt"day{day}"
if fileExists joinPath("src/", &"{module}.nim"): if fileExists joinPath("src/", &"{module}.nim"):
result.add parseStmt fmt"from {module} import nil" result.add parseStmt fmt"from {module} import nil"

View file

@ -5,7 +5,7 @@ var consoleLog = newConsoleLogger()
addHandler(consoleLog) addHandler(consoleLog)
addHandler(fileLog) addHandler(fileLog)
let cacheDir = joinPath(getEnv("XDG_CACHE_HOME", expandTilde("~/.cache")), "/aoc2020-cache") let cacheDir = joinPath(getEnv("XDG_CACHE_HOME", expandTilde("~/.cache")), "/aoc2020")
createDir(cacheDir) createDir(cacheDir)
# TODO: add login capabilities via `pass` for auto-cookie-retrieval? # TODO: add login capabilities via `pass` for auto-cookie-retrieval?
@ -14,7 +14,8 @@ proc requestAocContentAuthed(url: string): TaintedString =
let cookie = getEnv("ADVENT_OF_CODE_AUTH_COOKIE", readFile(expandTilde("~/.advent-of-code-auth-cookie"))) let cookie = getEnv("ADVENT_OF_CODE_AUTH_COOKIE", readFile(expandTilde("~/.advent-of-code-auth-cookie")))
let client = newHttpClient() let client = newHttpClient()
client.headers = newHttpHeaders({"cookie": cookie}) client.headers = newHttpHeaders({"cookie": cookie})
client.getContent(url) # client.getContent(url)
""
proc getInputFileStreamForDay*(day: int): FileStream = proc getInputFileStreamForDay*(day: int): FileStream =
# retrieve the input and dump it to a file if we don't have it yet # retrieve the input and dump it to a file if we don't have it yet