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

Published on 12 May 2024 09:40 PM

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

Source code in the seed7 programming language

$ include "seed7_05.s7i";

const string: start is "_###_##_#_#_#_#__#__";
 
const proc: main is func
  local
    var string: g0 is start;
    var string: g1 is start;
    var integer: generation is 0;
    var integer: i is 0;
  begin
    writeln(g0);
    for generation range 0 to 9 do
      for i range 2 to pred(length(g0)) do
        if g0[i-1] <> g0[i+1] then
          g1 @:= [i] g0[i];
        elsif g0[i] = '_' then
          g1 @:= [i] g0[i-1];
        else
          g1 @:= [i] '_'
        end if;
      end for;
      writeln(g1);
      g0 := g1;
    end for;
  end func;

  

You may also check:How to resolve the algorithm Literals/Floating point step by step in the Lasso programming language
You may also check:How to resolve the algorithm Arithmetic-geometric mean step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm N-queens problem step by step in the MiniZinc programming language
You may also check:How to resolve the algorithm Matrix digital rain step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Middle three digits step by step in the jq programming language