Jump to content

One-dimensional cellular automata: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.
(added GFA Basic example)
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.)
Line 3,619:
 
=={{header|REXX}}==
This REXX version will show (as a default)   40   generations,   or less if the generations of cellular automata repeat.
<lang rexx>/*REXX program displaysgenerates & displays N generations of one-dimensionalone─dimensional cellular automata. */
parse arg $ gens .; if $=='' | $==',' then $=001110110101010 /*useobtain optional arguments from the default?CL*/
if if gens$=='' | $=="," then gens$=40 001110110101010 /*Not "specified? Then use the " default.*/
if gens=='' | gens=="," then gens=40 /* " L=length($)-1 " " " " " /*adjusted len*/
 
do #=0 for gens /* process the one-dimensional /*process genscells.*/
say " generation" right(#,length(gens)) ' ' translate($, "#·", 10)
@=0 /*+ generation*/
@=0 do j=2 for L; x=substr($,j-1,3) /*obtain cell[↓] generation.*/
if x=do j=0112 | x==101for |length($) x==110- 1; then @ x=overlaysubstr(1,@$, j-1, 3) /*cellobtain lives.the cell.*/
if x==011 | x==101 | x==110 elsethen @=overlay(01, @, j) /*the cell deathlives. */
@=0 else @=overlay(0, @, j) /* " " dies. /*+ generation*/
end /*j*/
if $==@ then do; say right('repeats',40); leave; end /*it repeats? j*/
 
$=@ /*now use the next generation of cells.*/
if $==@ then do; say right('repeats', 40); leave; end /*does it repeat? */
end /*#*/
$=@ /*stick a fork in it, we're all/*now done.use the next generation of cells.*/</lang>
$=@ end /*#*/ /*nowstick usea thefork nextin generationit, of cellswe're all done. */</lang>
'''output''' when using the default input:
<pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.