Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moore Neighbourhood by Hanna_Hofman
def count_neighbours(grid, row, col):
neighbourhood = [[row-1+i//3,col+1-i%3]for i in list(range(9)) if i!=4]
result = 0
for i in neighbourhood:
if i[0]>=0 and i[1]>=0:
try: result += grid[i[0]][i[1]]
except: pass
return result
Oct. 14, 2014
Comments: