Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by BumKlatsch
def count_neighbours(grid, row, col):
result = 0
for i_row in range(max(0, row-1), min(len(grid), row + 2)):
for i_col in range(max(0, col - 1), min(len(grid[0]), col + 2)):
if (i_row, i_col) != (row, col):
result += 1 if grid[i_row][i_col] else 0
return result
Oct. 30, 2020