Code Kata is a term coined by Dave Thomas, co-author of the book The Pragmatic Programmer, in a bow to the Japanese concept of kata in the martial arts. A code kata is an exercise in programming which helps a programmer hone their skills through practice and repetition.
This Kata is based on KataRomanNumerals taken from codingdojo.org site, however I perform conversion in opposite deirection, from Roman to Arabic.
Write a function to convert from Roman numerals to Arabic numerals
I --> 1
X --> 10
VII --> 7
XXIII --> 23
XCIX --> 99
CLIX --> 159
What are the rules for writing roman numerals?
- In the Roman numeral system, the basic "digits" are the letters I, V, X, L, C, D, and M which represent the same numbers regardless of their position.
- Symbols are placed in order of value, starting with the largest values.
- When the higher numeral is placed before a lower numeral, the values of each Roman numeral are added.
- When smaller values precede larger values, the smaller values are subtracted from the larger values, and the result is added to the total.
- Do not repeat I, X, and C more than three times in a row (Number 4 on a Roman numeral clock is usually written as IIII).
- Symbols V, L, and D cannot appear more than once consecutively.
- Do not subtract a number from one that is more than 10 times greater: I may only precede V and X, X may only precede C and L, and C may only precede D and M.