Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Return or return not solution in Clear category for Moore Neighbourhood by veky
from itertools import product
def at(seq, k):
if k in range(len(seq)): yield seq[k]
def count_neighbours(grid, i, j):
def around():
for di, dj in filter(any, product({-1, 0, 1}, repeat=2)):
for row in at(grid, i + di): yield from at(row, j + dj)
return sum(around())
Aug. 16, 2015
Comments: