AoC 2020 D11: Seating System
| Problem statement | Source code | Tags: Cellular automata
← Previous Back to AoC Index Next →
Part 1
I've said it before: never represent cellular automata grids as physical 2D arrays. Always use a map from coordinates to cell states. Well in this problem, doing so allows us to completely ignore the floor cells. We can also precompute all neighbor cells for each seat, since it's going to be non-trivial in part 2.
Part 2
The only difference in part 2 is the neighbors2d function, which now has to look in each of the 8 directions until it finds a seat or hits the edge of the grid. Again, because whether a cell is a seat or floor is static, we can precompute the neighbors instead of recomputing during each evolution step.