How to resolve the algorithm One-dimensional cellular automata step by step in the Forth programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm One-dimensional cellular automata step by step in the Forth 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 Forth programming language
Source code in the forth programming language
: init ( bits count -- )
0 do dup 1 and c, 2/ loop drop ;
20 constant size
create state $2556e size init 0 c,
: .state
cr size 0 do
state i + c@ if ." #" else space then
loop ;
: ctable create does> + c@ ;
ctable rules $68 8 init
: gen
state c@ ( window )
size 0 do
2* state i + 1+ c@ or 7 and
dup rules state i + c!
loop drop ;
: life1d ( n -- )
.state 1 do gen .state loop ;
10 life1d
### ## # # # # #
# ##### # # #
## ## # #
## ### #
## # ##
## ###
## # #
## #
##
## ok
You may also check:How to resolve the algorithm Exceptions step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the Retro programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Arturo programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the Phix programming language
You may also check:How to resolve the algorithm 15 puzzle solver step by step in the PowerBASIC programming language