Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by MichalMarsalek
def count_neighbours(grid, row, col):
sizeY = len(grid)
sizeX = len(grid[0])
c = 0
for y in (-1, 0, 1):
for x in (-1, 0, 1):
if col + x in range(sizeX) and row + y in range(sizeY):
c += grid[row+y][col+x]
return c-grid[row][col]
Aug. 16, 2015