Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
slice solution in Clear category for Moore Neighbourhood by gyahun_dash
def count_neighbours(grid, row, col):
rs, cs = [slice(max(0, x - 1), x + 2) for x in (row, col)]
return sum(e for r in grid[rs] for e in r[cs]) - grid[row][col]
Oct. 4, 2014
Comments: