This commit is contained in:
Daniel Flanagan 2020-12-11 23:02:43 -06:00
parent 7d4f281c67
commit a85fb88c09
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
3 changed files with 17 additions and 4 deletions

View file

@ -9,4 +9,4 @@ proc solve_for_day(n: int) {.used.} =
when isMainModule: when isMainModule:
# solve_all() # solve_all()
solve_for_day(11) solve_for_day(12)

View file

@ -56,7 +56,7 @@ proc inBounds(g: Grid, x: int, y: int): bool =
x >= 0 and y >= 0 and y < g.len and x < g.row(y).len x >= 0 and y >= 0 and y < g.len and x < g.row(y).len
proc toSightSeat(g: Grid[Seat], x: int, y: int): SightSeat = proc toSightSeat(g: Grid[Seat], x: int, y: int): SightSeat =
echo "toSightSeat" #echo "toSightSeat"
result[0] = g.at(x, y) result[0] = g.at(x, y)
for vy in -1..1: for vy in -1..1:
for vx in -1..1: for vx in -1..1:
@ -67,7 +67,7 @@ proc toSightSeat(g: Grid[Seat], x: int, y: int): SightSeat =
tx += vx tx += vx
ty += vy ty += vy
if g.inBounds(tx, ty): result[1].add (x: tx, y: ty) if g.inBounds(tx, ty): result[1].add (x: tx, y: ty)
echo (x, y, result) #echo (x, y, result)
proc asSightGrid(s: Stream): SightGrid = proc asSightGrid(s: Stream): SightGrid =
let g = s.asGrid() let g = s.asGrid()
@ -106,7 +106,7 @@ proc part2*(s: Stream): int =
var ng: Grid[SightSeat] var ng: Grid[SightSeat]
var steps = 0 var steps = 0
while g != ng: while g != ng:
echo "Step ", steps #echo "Step ", steps
ng = g ng = g
g = g.stepSightGrid g = g.stepSightGrid
inc steps inc steps

13
2020/src/day12.nim Normal file
View file

@ -0,0 +1,13 @@
import streams, sequtils
type Dir = enum north, east, south, west
proc left(
proc part1*(s: Stream): int =
for l in s.lines:
echo l
9
proc part2*(s: Stream): int =
9