Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
3-liner: let's colour solution in Clear category for Moore Neighbourhood by przemyslaw.daniel
def count_neighbours(grid, row, col):
k = [(x+row, y+col) for x, y in ((1,0), (1,1), (0,1), (-1,0), (-1,-1), (0,-1), (1,-1), (-1,1))]
return sum([1 for x, y in k if 0 <= x < len(grid) and 0 <= y < len(grid[0]) and grid[x][y]])
April 18, 2017