Execute a Markov algorithm: Difference between revisions

Simplified D code
(Improved D code)
(Simplified D code)
Line 946:
=={{header|D}}==
{{trans|Perl}}
{{works with|D|2}}
<lang d>import std.stdio, std.array, std.file, std.regex, std.string;
 
void main() {
auto readBlocks(in string fn) {
auto rulesfn = readBlocks("markov_rules.txt");
string[][] resrules;
foreach (a; split(cast(string)read(fn), newline ~ newline))
resrules ~= a.splitlines();
return res;
}
 
void main() {
// read rule sets separated by a blank line
auto rules = readBlocks("markov_rules.txt");
 
auto tests = splitlines(cast(string)read("markov_tests.txt"));
 
Line 973 ⟶ 966:
auto copy = tests[i];
foreach (c; capt) {
tests[i] = replace(tests[i], .replace(c[0], c[2]);
if (c[1] == ".") break;
if (tests[i] != copy) breakgoto REDO;
if (tests[i] != copy)
goto REDO;
}
 
Anonymous user