

Within each grid 3 and 4 are compared with every element by scalar extension again. The result of the last step was a scalar containing one grid when paired with the vector 3 4 it is extended to give two grids. We can find these cells with a simple application of Equal to, relying on pervasion and scalar extension to distribute the data properly. So we're interested in cells with a sum of 3 or 4. This means that all cells which might be live in the next generation will have a sum of 3 (from the first rule) or 3 or 4 (from the second rule). Any cell, live or dead, with exactly three neighbours is live in the next generation.Any live cell with two neighbours lives, unchanged, to the next generation.For a dead cell the result is just the number of neighbours: For a live cell the sum is 1 more than the number of neighbours-for example, a 4 in the result means a cell has three neighbours.

Here APL's representation of Booleans as numbers is advantageous, since otherwise counting the number of true values would require converting them to numbers or using conditional logic. We sum all the grids at once by ravelling the shape 3 3 matrix of grids to obtain a 9-element vector otherwise Reduce would only allow us to sum rows or columns.

Now we can find out how many neighbours each cell in the original grid has by summing ( Plus Reduce) the corresponding elements in each of the 9 grids. The grid in the centre is our original grid, and the others give the neighbours above, below, left, right and diagonally.

To keep things simple let's consider the following 5-by-5 grid: To compute a new generation in the Game of Life we first need to find out how many neighbours each live cell has.
