Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by thealfest1
def count_neighbours(grid, row, col):
count = 0
for r in (-1, 0, 1):
y = row + r
for c in (-1, 0, 1):
if c == r == 0:
continue
x = col + c
if 0 <= x < len(grid[0]) and 0 <= y < len(grid):
count += grid[y][x]
return count
March 6, 2019
Comments: