From 496031e9c179e211d435fa18301670b0d96e5a76 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 11 Dec 2020 01:10:44 -0600 Subject: [PATCH] Day 11 part 1 --- 2020/src/day11.nim | 72 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) 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