RosettaCodeData/Task/Roman-numerals-Decode/Sidef/roman-numerals-decode-2.sidef
2017-09-25 22:28:19 +02:00

21 lines
474 B
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

func roman2arabic(digit) {
digit.uc.trans([
:M: '1000+',
:CM: '900+',
:D: '500+',
:CD: '400+',
:C: '100+',
:XC: '90+',
:L: '50+',
:XL: '40+',
:X: '10+',
:IX: '9+',
:V: '5+',
:IV: '4+',
:I: '1+',
]).split('+').map{.to_i}.sum;
}
 
%w(MCMXC MMVIII MDCLXVI).each { |roman_num|
say "#{roman_num}\t-> #{roman2arabic(roman_num)}";
}