One-dimensional cellular automata: Difference between revisions

Content added Content deleted
(added GFA Basic example)
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.)
Line 3,619: Line 3,619:


=={{header|REXX}}==
=={{header|REXX}}==
This REXX version will show (as a default) 40 generations, or less if the generations of cellular automata repeat.
This REXX version will show (as a default)   40   generations,   or less if the generations of cellular automata repeat.
<lang rexx>/*REXX program displays N generations of one-dimensional cellular automata.*/
<lang rexx>/*REXX program generates & displays N generations of one─dimensional cellular automata. */
parse arg $ gens .; if $=='' | $==',' then $=001110110101010 /*use default?*/
parse arg $ gens . /*obtain optional arguments from the CL*/
if gens=='' then gens=40 /* " " */
if $=='' | $=="," then $=001110110101010 /*Not specified? Then use the default.*/
L=length($)-1 /*adjusted len*/
if gens=='' | gens=="," then gens=40 /* " " " " " " */

do #=0 for gens /*process gens*/
do #=0 for gens /* process the one-dimensional cells.*/
say " generation" right(#,length(gens)) ' ' translate($,"#·",10)
say " generation" right(#,length(gens)) ' ' translate($, "#·", 10)
@=0 /*+ generation*/
do j=2 for L; x=substr($,j-1,3) /*obtain cell.*/
@=0 /* [↓] generation.*/
if x==011 | x==101 | x==110 then @=overlay(1,@,j) /*cell lives. */
do j=2 for length($) - 1; x=substr($, j-1, 3) /*obtain the cell.*/
else @=overlay(0,@,j) /*cell death. */
if x==011 | x==101 | x==110 then @=overlay(1, @, j) /*the cell lives. */
else @=overlay(0, @, j) /* " " dies. */
end /*j*/
if $==@ then do; say right('repeats',40); leave; end /*it repeats? */
end /*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 done. */</lang>
$=@ /*now use the next generation of cells.*/
end /*#*/ /*stick a fork in it, we're all done. */</lang>
'''output''' when using the default input:
'''output''' when using the default input:
<pre>
<pre>