Anonymous user
Straddling checkerboard: Difference between revisions
Updated D entry
(+ third D entry) |
(Updated D entry) |
||
Line 728:
===Dictionary-Based Version===
{{trans|Java}}
<lang d>import std.stdio, std.string, std.algorithm, std.regex, std.array, std.range, std.typecons;
immutable string[const string] val2key, key2val;
static this() pure /*nothrow @safe*/ {
"H":"0", "I":"36", "J":"37", "K":"38", "L":"2", "M":"4", ".":"78", "N":"39",
"/":"79", "O":"1", "0":"790", "P":"70", "1":"791", "Q":"71", "2":"792",
Line 739:
"6":"796", "V":"73", "7":"797", "W":"74", "8":"798", "X":"75", "9":"799",
"Y":"76", "Z":"77"];
val2key = aa;
key2val =
}
string encode(in string s) pure /*nothrow*/ @safe {
return s.toUpper.split("").map!(c => val2key.get(c, "")).join;
}
string decode(in string s) /*pure nothrow*/ @safe {
return s.matchAll("79.|3.|7.|.").map!(g => key2val.get(g[0], "")).join;
}
|