Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by Daniel_Pereira
def count_neighbours(grid, row, col):
from itertools import product
return sum( grid[i][j] for i, j in
((row+r, col+c) for r, c in product([-1, 0, 1], repeat=2) if (r or c))
if (i, j) in product(range(len(grid)), range(len(grid[0]))) )
Dec. 31, 2014
Comments: