Anonymous user
Execute a Markov algorithm: Difference between revisions
→{{header|D}}: update
(→{{header|REXX}}: included a CHANGESTR subroutine (function) as a link. -- ~~~~) |
(→{{header|D}}: update) |
||
Line 1,051:
void main() {
▲ string[] tests = readText("markov_tests.txt").splitLines();
▲ enum regex = ctRegex!(r"^([^#]*?)\s+->\s+(\.?)(.*)");
foreach (i, test; tests) {
string[][] capt;
foreach (line; rules[i]) {
auto m = line.match(regex);
if (!m.empty) capt ~= array(m.captures)[1 .. $];
}
REDO: auto copy = test;▼
▲ REDO:
▲ auto copy = test;
foreach (c; capt) {
test = test.replace(c[0], c[2]);
if (c[1] == ".") break;
if (test != copy)
}
writefln("%s\n%s\n", origtest, test);
}
}</lang>
{{out}}
<pre>I bought a
I bought a bag of apples from my brother.
I bought a B of As from T S.
I bought a bag of apples from T shop.
I bought a B of As W my Bgage from T S.
I bought a bag of apples with my money from T shop.
_1111*11111_
11111111111111111111
000000A000000
00011H1111000</pre>
|