One-dimensional cellular automata: Difference between revisions

Content added Content deleted
Line 3,369: Line 3,369:
=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>: nextGen(l)
<lang Oforth>: nextGen( l )
| i |
| i s |
l byteSize dup ->s String newSize
StringBuffer new
l size loop: i [
s loop: i [
l at( i 1- ) '#' ==
i 1 if=: [ 0 ] else: [ i 1- l byteAt '#' = ]
l at( i 1+ ) '#' == +
i l byteAt '#' = +
l at( i ) '#' == +
i s if=: [ 0 ] else: [ i 1+ l byteAt '#' = ] +
2 == ifTrue: [ '#' ] else: [ '_' ] over add
2 if=: [ '#' ] else: [ '_' ] over add
] ;
]
;
: gen( l n -- )
: gen(l, n) l dup println #[ nextGen dup println ] times(n) ;</lang>
l dup .cr #[ nextGen dup .cr ] times( n ) drop ;</lang>


{{out}}
{{out}}