Execute a Markov algorithm: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Cowgol) |
Not a robot (talk | contribs) (Add APL) |
||
Line 322: | Line 322: | ||
11111111111111111111 |
11111111111111111111 |
||
$ ./test_markov rules5 test5 |
$ ./test_markov rules5 test5 |
||
00011H1111000</pre> |
|||
=={{header|APL}}== |
|||
{{works with|Dyalog APL}} |
|||
<lang APL>markov←{ |
|||
trim←{(~(∧\∨⌽∘(∧\)∘⌽)⍵∊⎕UCS 9 32)/⍵} |
|||
rules←(~rules∊⎕UCS 10 13)⊆rules←80 ¯1 ⎕MAP ⍺ |
|||
rules←('#'≠⊃¨rules)/rules |
|||
rules←{ |
|||
norm←' '@(9=⎕UCS)⊢⍵ |
|||
spos←⍸' -> '⍷norm |
|||
pat←trim spos↑⍵ |
|||
repl←trim(spos+2)↓⍵ |
|||
term←'.'=⊃repl |
|||
term pat(term↓repl) |
|||
}¨rules |
|||
apply←{ |
|||
0=⍴rule←⍸∨/¨(2⊃¨⍺)⍷¨⊂⍵:⍵ |
|||
term pat repl←⊃⍺[⊃rule] |
|||
idx←(⊃⍸pat⍷⍵)-1 |
|||
⍺ ∇⍣(~term)⊢(idx↑⍵),repl,(idx+≢pat)↓⍵ |
|||
} |
|||
rules apply ⍵ |
|||
}</lang> |
|||
{{out}} |
|||
<pre> 'f:\ruleset1.mkv' markov 'I bought a B of As from T S.' |
|||
I bought a bag of apples from my brother. |
|||
'f:\ruleset2.mkv' markov 'I bought a B of As from T S.' |
|||
I bought a bag of apples from T shop. |
|||
'f:\ruleset3.mkv' markov 'I bought a B of As W my Bgage from T S.' |
|||
I bought a bag of apples with my money from T shop. |
|||
'f:\ruleset4.mkv' markov '_1111*11111_' |
|||
11111111111111111111 |
|||
'f:\ruleset5.mkv' markov '000000A000000' |
|||
00011H1111000</pre> |
00011H1111000</pre> |
||