diff --git a/2020/src/day11.nim b/2020/src/day11.nim index 7a4ee8f..7c7f0c7 100644 --- a/2020/src/day11.nim +++ b/2020/src/day11.nim @@ -1,7 +1,75 @@ -import streams +import streams, sequtils, strutils + +type + Seat = enum Floor, Empty, Occupied + Grid = seq[seq[Seat]] + +doAssert @[@[Occupied, Empty], @[Floor, Empty]] == @[@[Occupied, Empty], @[Floor, Empty]] + +proc gridSummary(g: Grid): (int, int) = + ## Used during debugging + var o, v = 0 + for y in 0..= 0 and sx >= 0 and sy < g.len and sx < g[sy].len: + result.add g[sy][sx] + +proc stepGrid(g: Grid): Grid = + #echo "Step" + for y in 0..= 5: + Empty + else: + Occupied + #echo (x, y, g[y][x], gridSummary(@[adj]), adj.gridLine, result[y][x]) proc part1*(s: Stream): int = - 0 + var g = s.asGrid + var ng: Grid + while g != ng: + echo "\n\nGrid:\n", g.gridSummary + ng = g + g = g.stepGrid + g.foldl(a.concat b).countIt(it == Occupied) + proc part2*(s: Stream): int = 0