This commit is contained in:
a 2020-12-17 13:09:26 -06:00
parent 798f8dddf3
commit 12e4a4b1c7
1 changed files with 5 additions and 5 deletions

View File

@ -9,14 +9,14 @@ def main(d):
)
# generate all tuples -1..1 in all dimensions
neighbors = [()] # list contains empty tuple which will be iterated over
neighboring = [()] # list contains empty tuple which will be iterated over
for _ in range(d):
neighbors = [
neighboring = [
t + (x,)
for x in [-1, 0, 1]
for t in neighbors
for t in neighboring
]
neighbors.remove(d * (0,)) # this is the center cell
neighboring.remove(d * (0,)) # this is the center cell
# do 6 iterations according to rules
from collections import Counter
@ -26,7 +26,7 @@ def main(d):
for t, count in Counter( # unpack the tuple and its count of neighboring active cells
tuple(map(sum, zip(t, n))) # add neighbors kernel to each active cell
for t in active
for n in neighbors
for n in neighboring
).items()
if count == 3 or t in active and count == 2
)