Anonymous user
Roman numerals/Decode: Difference between revisions
Updated D versions
(Updated D versions) |
|||
Line 371:
<lang d>import std.regex, std.algorithm;
int toArabic(in string s) /*pure nothrow*/ {
static
90, 50, 40, 10, 9, 5, 4, 1];
static
"L","XL","X","IX","V","IV","I"];
int arabic;
foreach (m; s.match(
arabic += weights[symbols.countUntil(m.hit)];
return arabic;
}
Line 391:
<lang d>import std.regex, std.algorithm;
immutable int[string] w2s;
nothrow static this() {
w2s = ["IX": 9, "C": 100, "D": 500, "CM": 900, "I": 1,
"XC": 90, "M": 1000, "L": 50, "CD": 400, "XL": 40,
"V": 5, "X": 10, "IV": 4];
}
int toArabic(in string s) /*pure nothrow*/ {
auto ms = match(s, regex(r"CM|CD|XC|XL|IX|IV|[MDCLXVI]", "g"));
return reduce!
}
|