Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by lexin13
def count_neighbours(grid, row, col):
return sum(grid[x][y]
for x in (row - 1, row, row + 1)
for y in (col - 1, col, col + 1)
if (x, y) != (row, col) and x in range(len(grid)) and y in range(len(grid[0]))
)
March 12, 2016