Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by gyahun_dash
def count_neighbours(grid, row, col):
rows = range(max(0, row - 1), min(row + 2, len(grid)))
cols = range(max(0, col - 1), min(col + 2, len(grid[0])))
return sum(grid[r][c] for r in rows for c in cols) - grid[row][col]
Sept. 30, 2014
Comments: