Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by optimus.531.creator
def count_neighbours(grid, row, col):
x = 0
for i in range(row-1,row+2):
for j in range(col-1, col+2):
if 0 <= i < len(grid) and 0 <= j < len(grid[0]) and grid[i][j] == 1:
x += 1
return x-1 if grid[row][col] == 1 else x
Nov. 22, 2015
Comments: