diff --git a/2020/src/day3.nim b/2020/src/day3.nim index 2b284a7..353a010 100644 --- a/2020/src/day3.nim +++ b/2020/src/day3.nim @@ -1,9 +1,23 @@ 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 = - 0 + sled(s, 3, 1) 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) diff --git a/2020/src/day_loader.nim b/2020/src/day_loader.nim index 93c0b20..251e8c0 100644 --- a/2020/src/day_loader.nim +++ b/2020/src/day_loader.nim @@ -7,6 +7,7 @@ macro loadDays(): untyped = let module = fmt"day{day}" if fileExists joinPath("src/", &"{module}.nim"): result.add parseStmt fmt"from {module} import nil" + # TODO: do I "need" to close these streams? solver_str = solver_str & &""" {day}: proc(): tuple[part1: int, part2: int] = echo "Day {day}"