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 |
<lang rexx>/*REXX program generates & displays N generations of one─dimensional cellular automata. */ |
||
parse arg $ gens . |
parse arg $ gens . /*obtain optional arguments from the CL*/ |
||
if $=='' | $=="," then $=001110110101010 /*Not specified? Then use the default.*/ |
|||
if gens=='' | gens=="," then gens=40 /* " " " " " " */ |
|||
do #=0 for 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 length($) - 1; x=substr($, j-1, 3) /*obtain the cell.*/ |
|||
if x==011 | x==101 | x==110 then @=overlay(1, @, j) /*the cell lives. */ |
|||
⚫ | |||
end /*j*/ |
|||
end /*j*/ |
|||
⚫ | |||
if $==@ then do; say right('repeats', 40); leave; end /*does it repeat? */ |
|||
end /*#*/ |
|||
$=@ /*now use the next generation of cells.*/ |
|||
⚫ | |||
'''output''' when using the default input: |
'''output''' when using the default input: |
||
<pre> |
<pre> |