Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Moore Neighbourhood by UFO665
def count_neighbours(grid, row, col):
return sum(grid[r][c] for r in range(row - 1, row + 2) for c in range(col - 1, col + 2)
if 0 <= r < len(grid) and 0 <= c < len(grid[0])) - grid[row][col]
Dec. 5, 2015