Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by artur_mierzwa
def count_neighbours(grid, row, col):
NEIGHBORS = ((-1, -1), (-1, 0), (-1, 1), (0, -1),
(0, 1), (1, -1), (1, 0), (1, 1))
ilosc = 0
for x in NEIGHBORS:
if (col+x[0] >= 0) and (col+x[0] < len(grid[0])) and (row+x[1] >= 0) and (row+x[1] < len(grid)):
ilosc +=grid[row+x[1]][col+x[0]]
return ilosc
Nov. 2, 2016