Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Shortened solution in Creative category for Moore Neighbourhood by suic
def count_neighbours(g, r, c):
ngcs = ((i, j) for i in (-1, 0, 1) for j in (-1, 0, 1))
cl, *mx = (r, c), len(g), len(g[0])
return sum([g[cl[0] + ngc[0]][cl[1] + ngc[1]] for ngc in ngcs
if any(ngc) and all((mx[i] > cl[i] + ngc[i] > -1 for i in (0, 1)))])
Jan. 17, 2015