Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Moore Neighbourhood by olonge
def count_neighbours(grid, row, col, N=(-1,0,1) ):
return sum ( grid[row+r][col+c]
for r in N
for c in N
if (r or c)
and 0 <= row+r < len(grid)
and 0 <= col+c < len(max(grid))
)
March 12, 2015
Comments: