FunctionRacerProblemsRace

Next Generation

HardNumPyPython

grid holds 0 (empty) and 1 (alive). Return the grid one step later:

A cell has up to 8 neighbors (diagonals count). Outside the grid everything is empty. No loops: for and while are not allowed.

Example 1

grid [[0,1,0],[0,1,0],[0,1,0]]
returns [[0,0,0],[1,1,1],[0,0,0]]

The middle cell keeps its 2 neighbors. The cells left and right of it each see 3 live cells and come alive. The top and bottom cells have 1 neighbor each.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems