I took this picture on the island of Gozo at the citadel of the city of Vittorija. The island is a small island that is part of the country of Malta.
Malta has been conquered by just about everyone at one point or another in their history, including the Romans, who presumably gave us roman numerals, and example of which you can see above the arch in the picture. But, there is a problem with this one. Do you know what it is?
As I was standing there looking at it I said to my self "What kind of Roman numeral is MDCCCCIV !? You are not supposed to have four of the same letter in a row. That breaks the rules. I'm pretty sure they were trying to represent the number 1904, The question is how would you correctly represent that if you followed the rules for roman numerals?
If you are not familiar with the rules let me tell you.
Writing numerals that decrease in values from left to right represents addition. For example MC represents 1000 + 100 = 1100 and XVI represents 10 + 5 + 1 or 16.
To write a number that would otherwise take repeating of a numeral 4 or more times there is a negation rule. Writing a smaller numeral to the left of a larger numeral causes the sign of then number on the left to be negative. for example IV is -1 + 5 = 4. Or MCMXIV is 1000 - 100 + 1000 + 10 - 1 + 5 or 1914.
Knowing all of that you can now re-write 1904 in a proper way.
DCCX-1: The correct roman numeral for 1904 is it is not MDCCCCIV.
DCCX-2: Match the roman numerals to the correct arabic numbers Make sure you follow all the rules.
Now that you are an expert in converting roman numerals to numbers its time to save yourself the trouble and write a program that does it for you. Here's an outline of what you should do.
Validate the number to make sure it follows all the rules. The number in the picture should cause you to print an error message.
If the roman numeral is valid then you should convert it to its Arabic equivalent.
Print out the roman numeral and its Arabic equivalent.
Hint: You will want to start by using a dictionary to map each single character roman numeral to the correct Arabic number.
DCCX-3: Can you explain why the dictionary used for this part uses the keys and values it does? Why does it need to be ordered? Why does this dictionary have more entries in it than the dictionary you used for part 1?
If you can do the first two parts then you are ready to do addition of roman numerals WITHOUT converting them to Arabic first! This one might take some extra research beyond what we have covered in class up to this point.
Convert any negated prefixes to additive suffixes. So, for example, IX would be rewritten to VIIII.
Concatenate the two strings you want to add.
If you've made it this far you have an answer but its not the simplest answer. Keep going.