June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,43 @@
import extensions.
import system'collections.
import system'routines.
static RomanDictionary = Dictionary new;
setAt("I", 1);
setAt("V", 5);
setAt("X", 10);
setAt("L", 50);
setAt("C", 100);
setAt("D", 500);
setAt("M", 1000).
literal extension $op
{
toRomanInt
[
var minus := 0.
var s := self upperCase.
var total := 0.
0 till(s length) do(:i)
[
var thisNumeral := RomanDictionary[s[i]] - minus.
if ((i >= s length - 1) || $(thisNumeral + minus >= RomanDictionary[s[i + 1]]))
[
total += thisNumeral.
minus := 0.
];
[
minus := thisNumeral
]
].
^ total
]
}
program =
[
console printLine("MCMXC: ", "MCMXC" toRomanInt).
console printLine("MMVIII: ", "MMVIII" toRomanInt).
console printLine("MDCLXVI:", "MDCLXVI" toRomanInt).
].