How to resolve the algorithm Execute a Markov algorithm step by step in the PicoLisp programming language
How to resolve the algorithm Execute a Markov algorithm step by step in the PicoLisp programming language
Table of Contents
Problem Statement
Create an interpreter for a Markov Algorithm.
Rules have the syntax:
There is one rule per line.
If there is a . (period) present before the
Rulesets Use the following tests on entries:
Sample text of: Should generate the output:
A test of the terminating rule Sample text of: Should generate:
This tests for correct substitution order and may trap simple regexp based replacement routines if special regexp characters are not escaped. Sample text of: Should generate:
This tests for correct order of scanning of rules, and may trap replacement routines that scan in the wrong order. It implements a general unary multiplication engine. (Note that the input expression must be placed within underscores in this implementation.) Sample text of: should generate the output:
A simple Turing machine, implementing a three-state busy beaver. The tape consists of 0s and 1s, the states are A, B, C and H (for Halt), and the head position is indicated by writing the state letter before the character where the head is. All parts of the initial tape the machine operates on have to be given in the input. Besides demonstrating that the Markov algorithm is Turing-complete, it also made me catch a bug in the C++ implementation which wasn't caught by the first four rulesets. This ruleset should turn into
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Execute a Markov algorithm step by step in the PicoLisp programming language
Source code in the picolisp programming language
(de markov (File Text)
(use (@A @Z R)
(let Rules
(make
(in File
(while (skip "#")
(when (match '(@A " " "-" ">" " " @Z) (replace (line) "@" "#"))
(link (cons (clip @A) (clip @Z))) ) ) ) )
(setq Text (chop Text))
(pack
(loop
(NIL
(find
'((R) (match (append '(@A) (car R) '(@Z)) Text))
Rules )
Text )
(T (= "." (cadr (setq R @)))
(append @A (cddr R) @Z) )
(setq Text (append @A (cdr R) @Z)) ) ) ) ) )
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Ruth-Aaron numbers step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the ActionScript programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Mirah programming language
You may also check:How to resolve the algorithm Remove lines from a file step by step in the D programming language