RosettaCodeData/Task/Roman-numerals-Encode/Elena/roman-numerals-encode.elena

33 lines
1 KiB
Text
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
import system'collections;
import system'routines;
import extensions;
import extensions'text;
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
static RomanDictionary = new Dictionary()
.setAt(1000, "M")
.setAt(900, "CM")
.setAt(500, "D")
.setAt(400, "CD")
.setAt(100, "C")
.setAt(90, "XC")
.setAt(50, "L")
.setAt(40, "XL")
.setAt(10, "X")
.setAt(9, "IX")
.setAt(5, "V")
.setAt(4, "IV")
.setAt(1, "I");
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
extension op
2018-06-22 20:57:24 +00:00
{
2019-09-12 10:33:56 -07:00
toRoman()
= RomanDictionary.accumulate(new StringWriter("I", self), (m,kv => m.replace(new StringWriter("I",kv.Key), kv.Value)));
2018-06-22 20:57:24 +00:00
}
2019-09-12 10:33:56 -07:00
public program()
{
console.printLine("1990 : ", 1990.toRoman());
console.printLine("2008 : ", 2008.toRoman());
console.printLine("1666 : ", 1666.toRoman())
}