Jump to content

One-dimensional cellular automata: Difference between revisions

Added Oz.
(Added Scala)
(Added Oz.)
Line 962:
Generation 9: __##________________
- : unit = ()
</pre>
 
=={{header|Oz}}==
<lang oz>declare
A0 = {List.toTuple unit "_###_##_#_#_#_#__#__"}
 
MaxGenerations = 9
 
Rules = unit('___':&_
'__#':&_
'_#_':&_
'_##':&#
'#__':&_
'#_#':&#
'##_':&#
'###':&_)
 
fun {Evolve A}
{Record.mapInd A
fun {$ I V}
Left = {CondSelect A I-1 &_}
Right = {CondSelect A I+1 &_}
Env = {String.toAtom [Left V Right]}
in
Rules.Env
end
}
end
 
fun lazy {Iterate X F}
X|{Iterate {F X} F}
end
in
for
I in 0..MaxGenerations
A in {Iterate A0 Evolve}
do
{System.showInfo "Gen. "#I#": "#{Record.toList A}}
end</lang>
 
Output:
<pre>Gen. 0: _###_##_#_#_#_#__#__
Gen. 1: _#_#####_#_#_#______
Gen. 2: __##___##_#_#_______
Gen. 3: __##___###_#________
Gen. 4: __##___#_##_________
Gen. 5: __##____###_________
Gen. 6: __##____#_#_________
Gen. 7: __##_____#__________
Gen. 8: __##________________
Gen. 9: __##________________
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.