Roman to Decimal Number conversion

739 Views Asked by At

I am trying to convert CIIXMXCVCII to decimal number. However, I am not getting it completely if it's a valid roman number representation or not. I tried this online tool: http://www.tools4noobs.com/online_tools/roman_decimal/ which says it's equivalent to 1277. However, roman representation of 1277 should be MCCLXXVII in my opinion. Can somebody clarify my doubt? Are both of these roman representation pointing to the same decimal number?

Thanks!

PS: Motivation for this comes from this mathematical joke: enter image description here

2

There are 2 best solutions below

7
On

The subtractive rule became “standard” only during the Middle Ages. But it's limited in application: only I, X and C can be used for subtraction (once) and next to a symbol of the “next size”:

  • I can be used before V or X
  • X can be used before L or C
  • C can be used before D or M

(see http://en.wikipedia.org/wiki/Roman_numerals)

Thus $1999$ can be represented as MCMXCIX, not as MIM. The notation is in order from the highest units to the lowest:

M CM XC IX

that would be, without the abbrevations,

M D CCCC L XXXX V IIII

In Latin, the number would be spelled mille nongenti nonaginta novem and the number system reflected the names. So IM would mean nothing: Romans were not really good with arithmetic. ;) This can be found in modern usage, however.

I can't see any sensible way to parse CIIXMXCVCII. The tool you mention converts MIIM into $2000$ and IMIIM into $1999$, so I'm under the impression that it discards “illegal” subtractive symbols; if we remove II (as CIIX is converted to $110$) we get CXMXCVCII: $100+990+90+5+100+2=1287$ so I don't see where $1277$ comes from. Another example is VVCVCIV that's converted to $199$, while removing the first C gives VVVCIV that's converted to $109$.

0
On

You can sensibly parse it by recursively applying a hypothetical rule "any pending smaller number is subtracted from a larger subsequent number" by using a stack. (WikiPedia does say double subtractives are known...)

C = 100 (push 100)
II = 2 (push 2)
X = 8 (10 - pop 2 = push 8)
M (1000 - 108) (pop 100 & 8, push 1000 - 108 = 892) 
X = push 10
C = 90  (pop 10, push 90)
V = push 5
C = 95  (pop 5, push 95)
II = 2 push 2

At end, pop and add all numbers = 2 + 95 + 90 + 892 = 1079

E.g. IVX = 10 - 4 = 6.

Not saying my method is officially sanctioned in any way - but it is a possible interpretation and will yield a number in any case.