2020-12-03 09:54:58 -06:00
|
|
|
import streams
|
|
|
|
|
2020-12-03 10:13:34 -06:00
|
|
|
proc sled(s: Stream, velx: int, vely: int): int =
|
2020-12-03 10:20:02 -06:00
|
|
|
var xpos, ypos: int
|
2020-12-03 10:13:34 -06:00
|
|
|
for line in s.lines():
|
|
|
|
ypos += 1
|
|
|
|
if (ypos - 1) mod vely > 0:
|
|
|
|
continue
|
|
|
|
if line[xpos mod line.len()] == '#':
|
|
|
|
result += 1
|
|
|
|
xpos += velx
|
2020-12-03 09:57:12 -06:00
|
|
|
|
2020-12-03 09:54:58 -06:00
|
|
|
proc part1*(s: Stream): int =
|
2020-12-03 10:13:34 -06:00
|
|
|
sled(s, 3, 1)
|
2020-12-03 09:54:58 -06:00
|
|
|
|
|
|
|
proc part2*(s: Stream): int =
|
2020-12-03 10:13:34 -06:00
|
|
|
result = part1(s)
|
|
|
|
for vels in [(1, 1), (5, 1), (7, 1), (1, 2)]:
|
2020-12-03 10:20:02 -06:00
|
|
|
setPosition(s, 0)
|
2020-12-03 10:13:34 -06:00
|
|
|
let (velx, vely) = vels
|
|
|
|
result *= sled(s, velx, vely)
|