Last active
November 20, 2021 21:20
-
-
Save aarondewindt/d8e5a25d460a3b68b12da667f22a1599 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import numpy.testing as npt | |
from itertools import product | |
b = np.array([ | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 1, 0, 0, 0, 0, 1, 0, 1, 0,], | |
[0, 0, 1, 0, 0, 0, 0, 1, 0, 0,], | |
[0, 0, 0, 1, 0, 0, 0, 0, 1, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 1, 0, 1, 0, 0, 1, 0, 1, 0,], | |
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 1, 0, 1, 0, 0, 0, 0, 1, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 1, 0, 1, 0, 0, 1, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 1, 0, 1, 0, 0, 0, 0, 1, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
]) | |
b_correct = np.array([ | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0,], | |
[0, 0, 1, 0, 0, 0, 0, 1, 1, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 1, 0, 1, 0, 0, 0, 1, 0, 0,], | |
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,], | |
]) | |
b=(3==(n:=sum(np.roll(b,s,(0,1))for s in product(*2*[(-1,0,1)]))))|(n==4)&b | |
print(b) | |
npt.assert_equal(b, b_correct) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment