Jump to content

One-dimensional cellular automata: Difference between revisions

Added Arturo implementation
(Added Arturo implementation)
Line 322:
Generation 8 __##________________
</pre>
 
=={{header|Arturo}}==
 
<lang rebol>evolve: function [arr][
ary: [0] ++ arr ++ [0]
ret: new []
loop 1..(size ary)-2 'i [
a: ary \ i-1
b: ary \ i
c: ary \ i+1
 
if? 2 = a+b+c -> 'ret ++ 1
else -> 'ret ++ 0
]
ret
]
 
printIt: function [arr][
print replace replace join map arr => [to :string] "0" "_" "1" "#"
]
 
arr: [0 1 1 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0]
printIt arr
 
newGen: evolve arr
while [newGen <> arr][
arr: newGen
newGen: evolve arr
printIt newGen
]</lang>
 
{{out}}
 
<pre>_###_##_#_#_#_#__#__
__##___##_#_#_______
__##___###_#________
__##___#_##_________
__##____###_________
__##____#_#_________
__##_____#__________
__##________________
__##________________</pre>
 
=={{header|AutoHotkey}}==
1,532

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.