This commit is contained in:
Daniel Flanagan 2020-12-03 10:13:34 -06:00
parent e52c644532
commit fa6c830b81
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
2 changed files with 18 additions and 3 deletions

View file

@ -1,9 +1,23 @@
import streams import streams
let sledSlope = (3, 1) proc sled(s: Stream, velx: int, vely: int): int =
setPosition(s, 0)
result = 0
var xpos = 0
var ypos = 0
for line in s.lines():
ypos += 1
if (ypos - 1) mod vely > 0:
continue
if line[xpos mod line.len()] == '#':
result += 1
xpos += velx
proc part1*(s: Stream): int = proc part1*(s: Stream): int =
0 sled(s, 3, 1)
proc part2*(s: Stream): int = proc part2*(s: Stream): int =
0 result = part1(s)
for vels in [(1, 1), (5, 1), (7, 1), (1, 2)]:
let (velx, vely) = vels
result *= sled(s, velx, vely)

View file

@ -7,6 +7,7 @@ macro loadDays(): untyped =
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"
# TODO: do I "need" to close these streams?
solver_str = solver_str & &""" solver_str = solver_str & &"""
{day}: proc(): tuple[part1: int, part2: int] = {day}: proc(): tuple[part1: int, part2: int] =
echo "Day {day}" echo "Day {day}"