How to resolve the algorithm Wireworld step by step in the PicoLisp programming language
How to resolve the algorithm Wireworld step by step in the PicoLisp programming language
Table of Contents
Problem Statement
Wireworld is a cellular automaton with some similarities to Conway's Game of Life. It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneously. The cell transition rules are this:
Create a program that reads a Wireworld program from a file and displays an animation of the processing. Here is a sample description file (using "H" for an electron head, "t" for a tail, "." for a conductor and a space for empty) you may wish to test with, which demonstrates two cycle-3 generators and an inhibit gate: While text-only implementations of this task are possible, mapping cells to pixels is advisable if you wish to be able to display large designs. The logic is not significantly more complex.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Wireworld step by step in the PicoLisp programming language
Source code in the picolisp programming language
(load "@lib/simul.l")
(let
(Data (in "wire.data" (make (while (line) (link @))))
Grid (grid (length (car Data)) (length Data)) )
(mapc
'((G D) (mapc put G '(val .) D))
Grid
(apply mapcar (flip Data) list) )
(loop
(disp Grid T
'((This) (pack " " (: val) " ")) )
(wait 1000)
(for Col Grid
(for This Col
(case (=: next (: val))
("H" (=: next "t"))
("t" (=: next "."))
("."
(when
(>=
2
(cnt # Count neighbors
'((Dir) (= "H" (get (Dir This) 'val)))
(quote
west east south north
((X) (south (west X)))
((X) (north (west X)))
((X) (south (east X)))
((X) (north (east X))) ) )
1 )
(=: next "H") ) ) ) ) )
(for Col Grid # Update
(for This Col
(=: val (: next)) ) )
(prinl) ) )
You may also check:How to resolve the algorithm Draw a cuboid step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Equilibrium index step by step in the Batch File programming language
You may also check:How to resolve the algorithm Read a file line by line step by step in the APL programming language
You may also check:How to resolve the algorithm Short-circuit evaluation step by step in the C programming language
You may also check:How to resolve the algorithm Quaternion type step by step in the D programming language