Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
add zeros around of grid and sum slices solution in Clear category for Moore Neighbourhood by kdim
def count_neighbours(g, r, c):
l = len(g[0])
m = [(0,)+i+(0,) for i in ((0,)*l,)+g+((0,)*l,)]
return sum(m[r][c:c+3]+m[r+1][c:c+3]+m[r+2][c:c+3])-m[r+1][c+1]
"""
add zeros around of grid and sum slices
00000
101 01010
001 --> 00010
111 01110
00000
"""
Jan. 24, 2021
Comments: