Next Generation
grid holds 0 (empty) and 1 (alive). Return the grid one step later:
- a live cell with 2 or 3 live neighbors stays alive,
- an empty cell with exactly 3 live neighbors comes alive,
- every other cell is empty.
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
1 <= rows, columns <= 12- Every cell is 0 or 1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Runs of Equal ValuesHard
- Two Closest PointsHard
- Vote of the NearestHard
- Above Average CountBeginner
- Average TemperatureBeginner
- Black and WhiteBeginner
- Celsius to FahrenheitBeginner
- Clip ScoresBeginner