Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by Tinus_Trotyl
def count_neighbours(grid, y, x):
BLOCK = [(x-1, y-1), (x+0, y-1), (x+1, y-1),
(x-1, y+0), (x+1, y+0),
(x-1, y+1), (x+0, y+1), (x+1, y+1)]
return sum([grid[Yc][Xc] for Xc, Yc in BLOCK if 0 <= Xc < len(grid[0]) and 0 <= Yc < len(grid)])
Dec. 27, 2019
Comments: