Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Straightforward solution in Clear category for Moore Neighbourhood by nickie
def count_neighbours(grid, row, col):
N, M = len(grid), len(grid[0])
NEIGHBOURS = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
return sum(0 <= row+i < N and 0 <= col+j < M and grid[row+i][col+j]
for i, j in NEIGHBOURS)
Oct. 6, 2014
Comments: