One-dimensional cellular automata: Difference between revisions
Content added Content deleted
m (→{{header|jq}}: mention use of recurse to continue until quiescence) |
|||
Line 2,391: | Line 2,391: | ||
__##________________ |
__##________________ |
||
__##________________</pre> |
__##________________</pre> |
||
'''Using nested functions and method calling style:''' |
|||
<pre> |
|||
proc cell_automata = |
|||
proc evolve_into(X, T : var string) = |
|||
for i in X.low..X.high: |
|||
let |
|||
alive = X[i] == 'o' |
|||
left = if i == X.low: false else: X[i - 1] == 'o' |
|||
right = if i == X.high: false else: X[i + 1] == 'o' |
|||
T[i] = |
|||
if alive: if left xor right: 'o' else: '.' |
|||
else: if left and right: 'o' else: '.' |
|||
var |
|||
X = ".ooo.oo.o.o.o.o..o.." |
|||
T = X |
|||
for i in 1..10: |
|||
X.echo |
|||
X.evolve_into T |
|||
T.swap X |
|||
</pre> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |