Christmas is over, so we get rid of the Christmas Tree.
Today I want to show You another Code Kata: Roman Numerals. The task seems to be quite easy. Write a program which converts a decimal number into a string which contains the equivalent as a roman literal. E.g. convert 1984 into MCMLXXXIV.
The requirements
We just use the characters from I to M.
Symbol | I | V | X | L | C | D | M |
---|---|---|---|---|---|---|---|
Value | 1 | 5 | 10 | 50 | 100 | 500 | 1,000 |
We first write a simple conversion function which ignores the abbreviation syntax, so instead of IX for 9 we write VIIII. To do so we use integer division and modulo operation. We start with the highest number and work our way down. Have a look: Continue reading “Code Kata: Roman Numeral – Part 1”