tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,32 @@
import std.stdio, std.array, std.file, std.regex, std.string,
std.range;
void main() {
string[][] rules = readText("markov_rules.txt").splitLines()
.split("");
auto tests = readText("markov_tests.txt").splitLines();
auto re = ctRegex!(r"^([^#]*?)\s+->\s+(\.?)(.*)"); // 130 MB RAM.
auto pairs = zip(StoppingPolicy.requireSameLength, tests, rules);
foreach (test, rule; pairs) {
auto origTest = test.dup;
string[][] capt;
foreach (line; rule) {
auto m = line.match(re);
if (!m.empty)
capt ~= m.captures.array()[1 .. $];
}
REDO:
auto copy = test;
foreach (c; capt) {
test = test.replace(c[0], c[2]);
if (c[1] == ".")
break;
if (test != copy)
goto REDO;
}
writefln("%s\n%s\n", origTest, test);
}
}