Skip to content

Instantly share code, notes, and snippets.

@koalatux
Created March 6, 2019 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koalatux/af66c8e370ce0f1b8ec6d0bb3372fde1 to your computer and use it in GitHub Desktop.
Save koalatux/af66c8e370ce0f1b8ec6d0bb3372fde1 to your computer and use it in GitHub Desktop.
from scipy.signal import convolve2d
KERNEL = [[2, 2, 2],
[2, 1, 2],
[2, 2, 2]]
def iterate_grid(grid):
return abs(convolve2d(grid, KERNEL, mode='same') - 6) < 2
input_grid = [[False, True, False, False],
[False, False, True, False],
[True, True, True, False],
[False, False, False, False]]
print(iterate_grid(input_grid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment