Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by magda_kudrycka
def count_neighbours(grid, row, col):
sasiadki = (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, -1), (-1, 1), (1, -1)
licznik = 0
for i in sasiadki:
c = col + i[1]
r = row + i[0]
if r >= 0 and r < len(grid):
if c >= 0 and c < len(grid[0]):
licznik += grid[r][c]
return licznik
Nov. 27, 2016