Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by spoty
def count_neighbours(g, x, y):
return sum(g[x+i][y+j] for i in (-1,0,1)
for j in (-1,0,1)
if (i != 0 or j != 0) and 0 <= x+i < len(g) and 0 <= y+j < len(g[0]))
Oct. 17, 2014
Comments: