Jump to content

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*/ {
val2keyimmutable aa = ["A":"30", "B":"31", "C":"32", "D":"33", "E":"5", "F":"34", "G":"35",
"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 = val2keyaa.byValuebyKeyValue.zipmap!(val2keyt => tuple(t.value, t.byKeykey)).assocArray;
}
 
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;
}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.