One-dimensional cellular automata: Difference between revisions
Content added Content deleted
(+ third D version) |
No edit summary |
||
Line 3,071: | Line 3,071: | ||
008: __##________________ |
008: __##________________ |
||
Sample stable after 8 generations.</pre> |
Sample stable after 8 generations.</pre> |
||
=={{header|Wart}}== |
|||
===Simple=== |
|||
<lang python>def (gens n l) |
|||
prn l |
|||
repeat n |
|||
zap! gen l |
|||
prn l |
|||
def (gen l) |
|||
with (a nil b nil c l.0) |
|||
collect nil # won't insert paren without second token |
|||
each x cdr.l |
|||
shift! a b c x |
|||
yield (next a b c) |
|||
yield (next b c nil) |
|||
def (next a b c) # next state of b given neighbors a and c |
|||
if (and a c) not.b |
|||
(or a c) b</lang> |
|||
Output looks a little ugly: |
|||
<pre>ready! type in an expression, then hit enter twice. ctrl-d exits. |
|||
gens 5 '(1 1 1 nil 1) |
|||
(1 1 1 nil 1) |
|||
(1 nil 1 1 nil) |
|||
(nil 1 1 1 nil) |
|||
(nil 1 nil 1 nil) |
|||
(nil nil 1 nil nil) |
|||
(nil nil nil nil nil)</pre> |
|||
=={{header|XPL0}}== |
=={{header|XPL0}}== |