Jump to content

One-dimensional cellular automata: Difference between revisions

(Nimrod -> Nim)
Line 2,477:
Generation 9: __##________________
- : unit = ()
</pre>
 
=={{header|Oforth}}==
 
<lang Oforth>func: nextGen(l)
{
| i |
ListBuffer new dup add(0)
2 l size 1 - for: i [
0 l at(i 1 -) l at(i) + l at(i 1 +) + 2 == ifTrue: [ 1 + ] over add
]
dup add(0)
}
 
func: gen(l, n)
{
l println
[ 0 ] l + [ 0 ] +
#[ nextGen dup dup size 1 - 2 rot extract println ] times(n)
}</lang>
 
{{out}}
<pre>
gen([ 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0 ], 10)
[1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0]
[1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
</pre>
 
1,015

edits

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