One-dimensional cellular automata: Difference between revisions
Content added Content deleted
(Nimrod -> Nim) |
|||
Line 2,477: | Line 2,477: | ||
Generation 9: __##________________ |
Generation 9: __##________________ |
||
- : unit = () |
- : 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> |
</pre> |
||