Execute a Markov algorithm: Difference between revisions

Added PicoLisp
(Added PicoLisp)
Line 887:
 
print $input;</lang>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(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)) ) ) ) ) )</lang>
Output:
<pre>: (markov "r1" "I bought a B of As from T S.")
-> "I bought a bag of apples from my brother."
 
: (markov "r2" "I bought a B of As from T S.")
-> "I bought a bag of apples from T shop."
 
: (markov "r3" "I bought a B of As W my Bgage from T S.")
-> "I bought a bag of apples with my money from T shop."
 
: (markov "r4" "_1111*11111_")
-> "11111111111111111111"
 
: (markov "r5" "000000A000000")
-> "00011H1111000"</pre>
 
=={{header|Python}}==
Anonymous user