One-dimensional cellular automata: Difference between revisions
Content added Content deleted
m (→Python: Sum neighbours == 2: Whoops!) |
(→Python: Sum neighbours == 2: Simpler initialization.) |
||
Line 2,402: | Line 2,402: | ||
===Python: Sum neighbours == 2=== |
===Python: Sum neighbours == 2=== |
||
This example makes use of the observation that a cell is alive in the next generation if the sum with its current neighbours of alive cells is two. |
This example makes use of the observation that a cell is alive in the next generation if the sum with its current neighbours of alive cells is two. |
||
<lang python>>>> gen = [ |
<lang python>>>> gen = [ch == '#' for ch in '_###_##_#_#_#_#__#__'] |
||
>>> for n in range(10): |
>>> for n in range(10): |
||
print(''.join('#' if cell else '_' for cell in gen)) |
print(''.join('#' if cell else '_' for cell in gen)) |