One-dimensional cellular automata: Difference between revisions

Updated to compile with Nim 1.4. Changed indentation and identifiers to conform to guidelines. Added missing call to procedure.
(Updated to compile with Nim 1.4: replaced "repeatChar" by "repeat" from module "strutils".)
(Updated to compile with Nim 1.4. Changed indentation and identifiers to conform to guidelines. Added missing call to procedure.)
Line 3,320:
 
'''Using nested functions and method calling style:'''
<lang Nim>proc cellAutomata =
<pre>
proc evolve_intoevolveInto(Xx, Tt : var string) =
proc cell_automata =
for i in Xx.low..Xx.high:
proc evolve_into(X, T : var string) =
let
for i in X.low..X.high:
alive = x[i] == let 'o'
left = if i == x.low: alivefalse =else: Xx[i - 1] == 'o'
left right = if i == Xx.lowhigh: false else: Xx[i -+ 1] == 'o'
t[i] =
right = if i == X.high: false else: X[i + 1] == 'o'
if alive: (if left T[i]xor =right: 'o' else: '.')
else: if alive: (if left xorand right: 'o' else: '.')
else: if left and right: 'o' else: '.'
 
var
Xx = ".ooo.oo.o.o.o.o..o.."
Tt = Xx
 
for i in 1..10:
Xx.echo
Xx.evolve_intoevolveInto Tt
swap t, T.swap Xx
 
</pre>
cellAutomata()
</prelang>
 
{{out}}
<pre>.ooo.oo.o.o.o.o..o..
.o.ooooo.o.o.o......
..oo...oo.o.o.......
..oo...ooo.o........
..oo...o.oo.........
..oo....ooo.........
..oo....o.o.........
..oo.....o..........
..oo................
..oo................</pre>
 
=={{header|OCaml}}==
Anonymous user