How to resolve the algorithm One-dimensional cellular automata step by step in the ERRE programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm One-dimensional cellular automata step by step in the ERRE 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 ERRE programming language

Source code in the erre programming language

PROGRAM ONEDIM_AUTOMATA

! for rosettacode.org
!

!VAR I,J,N,W,K

!$DYNAMIC
DIM X[0],X2[0]

BEGIN

   DATA(20,0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0)

   PRINT(CHR$(12);)
   N=20      ! number of generation required
   READ(W)
   !$DIM X[W+1],X2[W+1]
   FOR I=1 TO W DO
      READ(X[I])
   END FOR
   FOR K=1 TO N DO
      PRINT("Generation";K;TAB(16);)
      FOR J=1 TO W DO
         IF X[J]=1 THEN PRINT("#";)  ELSE PRINT("_";) END IF
         IF X[J-1]+X[J]+X[J+1]=2 THEN X2[J]=1 ELSE X2[J]=0 END IF
      END FOR
      PRINT
      FOR J=1 TO W DO
         X[J]=X2[J]
      END FOR
   END FOR
END PROGRAM

  

You may also check:How to resolve the algorithm Factors of an integer step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Input loop step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Julia set step by step in the Ring programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Python programming language