Day 3
This commit is contained in:
parent
e52c644532
commit
fa6c830b81
|
@ -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)
|
||||||
|
|
|
@ -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}"
|
||||||
|
|
Loading…
Reference in a new issue