Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
try except solution in Clear category for Moore Neighbourhood by xiongbiao
# migrated from python 2.7
def count_neighbours(grid, row, col):
s = 0
for x in range(-1,2):
for y in range(-1,2):
try:
if row+x>=0 and col+y>=0:
s += grid[row+x][col+y]
except Exception as e:
pass
s-=grid[row][col]
return s
Nov. 27, 2014
Comments: