June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
43
Task/Roman-numerals-Decode/Elena/roman-numerals-decode.elena
Normal file
43
Task/Roman-numerals-Decode/Elena/roman-numerals-decode.elena
Normal 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).
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue