Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by samulih
def count_neighbours(grid, row, col, coords=(-1, 0, 1)):
return sum(grid[row+j][col+i] for i in coords for j in coords if (i or j) and
0 <= col+i < len(grid[0]) and 0 <= row+j < len(grid))
Oct. 2, 2014
Comments: