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

Published on 12 May 2024 09:40 PM

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

Source code in the action! programming language

CHAR FUNC CalcCell(CHAR prev,curr,next)
  IF prev='. AND curr='# AND next='# THEN
    RETURN ('#)
  ELSEIF prev='# AND curr='. AND next='# THEN
    RETURN ('#)
  ELSEIF prev='# AND curr='# AND next='. THEN
    RETURN ('#)
  FI
RETURN ('.)

PROC NextGeneration(CHAR ARRAY s)
  BYTE i
  CHAR prev,curr,next

  IF s(0)<4 THEN RETURN FI
  prev=s(1) curr=s(2) next=s(3)
  i=2
  DO
    s(i)=CalcCell(prev,curr,next)
    i==+1
    IF i=s(0) THEN EXIT FI
    prev=curr curr=next next=s(i+1)
  OD
RETURN

PROC Main()
  DEFINE MAXGEN="9"
  CHAR ARRAY s=".###.##.#.#.#.#..#.."
  BYTE i

  FOR i=0 TO MAXGEN
  DO
    PrintF("Generation %I: %S%E",i,s)
    IF i
      NextGeneration(s)
    FI
  OD
RETURN

  

You may also check:How to resolve the algorithm Fibonacci n-step number sequences step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the Ezhil programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Inconsummate numbers in base 10 step by step in the Julia programming language
You may also check:How to resolve the algorithm Summarize primes step by step in the Julia programming language