Roman to Decimal
(Challenge added 535 days ago.)
Lazy Cows Don't Moo.
The Problem
In this challenge, you will be given a number in roman numeral form and must print out its integer value.
Recently there was a perl golf challenge relating to roman numerals at Fonality, most people relied on a formula to convert from decimal to roman, so for those who didn't get a chance to enter due to being busy over the holidays or just not knowing perl, here is your chance to get in on the roman numeral action. It should be similar but completely different.
More Information
Roman numerals are composed of the capital letters IVXLCDM corresponding to values 1, 5, 10, 50, 100, 500, 1000. The value of a roman numeral is the sum of each letter's value.
However, Roman numerals are not purely additive. Instead of using four repetitions of a single symbol (For example, using IIII to represent 4), we instead use IV, which can be read as '5 minus 1'. Similarly, we use XC for 90, CD for 400 etc. Note there are some restrictions on this. For example, we don't write IM for 999. For more information, check out Wikipedia's Roman numerals article and Mathworld's Roman numerals page
- The input will be in the range of I to MMMCMXCIX (1 to 3999)
- The input will be followed by the newline character.
- There are 25 test cases. In order for your script to be successful it must pass every case.
Examples
Of the 25 runs your submission will be tested on, the first 17 will always ask you to convert the same numeral :- Run 1 - MMMCCXC
- Run 2 - MCMVII
- Run 3 - MMCDXLVII
- Run 4 - MMCMLXXXIV
- Run 5 - MXCVI
- Run 6 - MCMIV
- Run 7 - MMDII
- Run 8 - M
- Run 9 - MMDLXXIX
- Run 10 - MMMLXXXVIII
- Run 11 - MMDCCXCIX
- Run 12 - MMDVI
- Run 13 - MMMDCCLVII
- Run 14 - MMMCCLXXXIII
- Run 15 - MCDXL
- Run 16 - MMD
- Run 17 - DCLI
In the remaining 8 tests, your submission will be given a random numeral to convert. Click here to see a random test case. Reload the page to get another.
Thanks
Thanks to Flagitious for suggesting, submitting and writing the description for this challenge!
