How to resolve the algorithm One-dimensional cellular automata step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm One-dimensional cellular automata step by step in the REXX programming language
Table of Contents
Problem Statement
Assume an array of cells with an initial distribution of live and dead cells, and imaginary cells off the end of the array having fixed values. Cells in the next generation of the array are calculated based on the value of the cell and its left and right nearest neighbours in the current generation. If, in the following table, a live cell is represented by 1 and a dead cell by 0 then to generate the value of the cell at a particular index in the array of cellular values you use the following table:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm One-dimensional cellular automata step by step in the REXX programming language
Source code in the rexx programming language
/*REXX program generates & displays N generations of one─dimensional cellular automata. */
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 /* process the one-dimensional cells.*/
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. */
else @=overlay(0, @, j) /* " " dies. */
end /*j*/
if $==@ then do; say right('repeats', 40); leave; end /*does it repeat? */
$=@ /*now use the next generation of cells.*/
end /*#*/ /*stick a fork in it, we're all done. */
You may also check:How to resolve the algorithm Map range step by step in the SparForte programming language
You may also check:How to resolve the algorithm Leonardo numbers step by step in the Odin programming language
You may also check:How to resolve the algorithm Image noise step by step in the PureBasic programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the C# programming language
You may also check:How to resolve the algorithm Associative array/Merging step by step in the Crystal programming language