One-dimensional cellular automata: Difference between revisions
Content added Content deleted
(→Python: Sum neighbours == 2: Simpler initialization.) |
(→{{header|REXX}}: added the REXX language. -- ~~~~) |
||
Line 2,499: | Line 2,499: | ||
(0 0 1 1 0 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 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) |#</lang> |
(0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) |#</lang> |
||
=={{header|REXX}}== |
|||
This REXX version will show (as a default) 40 generations, or less if the generations of cellular automata repeat. |
|||
<lang rexx>/*REXX pgm displays generations of one-dimensional cellular automata. */ |
|||
arg $ limit .; if $=='' | $==',' then $=001110110101010 /*default*/ |
|||
if limit=='' then limit=40 /*default*/ |
|||
do gen=0 to limit |
|||
say ' generation' right(gen,length(limit)) ' ' translate($,'#·',10) |
|||
@='·' /*next gener.*/ |
|||
do j=2 to length($); x=substr($,j-1,3) /*get a cell.*/ |
|||
if x==011 | x==101 | x==110 then @=overlay(1,@,j) /*cell lives.*/ |
|||
else @=overlay(0,@,j) /*cell dies.*/ |
|||
end /*j*/ |
|||
if $==@ then do; say right('repeats',40); leave; end /*it repeats?*/ |
|||
$=@ /*now use the next gen of cells. */ |
|||
end /*gen*/ |
|||
/*stick a fork in it, we're done.*/</lang> |
|||
'''output''' when using the default input |
|||
<pre style="overflow:scroll"> |
|||
generation 0 ··###·##·#·#·#· |
|||
generation 1 ··#·#####·#·#·· |
|||
generation 2 ···##···##·#··· |
|||
generation 3 ···##···###···· |
|||
generation 4 ···##···#·#···· |
|||
generation 5 ···##····#····· |
|||
generation 6 ···##·········· |
|||
repeats |
|||
</pre> |
|||
=={{header|Retro}}== |
=={{header|Retro}}== |
||
<lang Retro>{{ |
<lang Retro>{{ |