2005/02/03

Roman Numerals

As we can see, this vintage numbering system is still vividly flying around. For instance, the coming Super Bowl, X_X_XIX means 39th.

Symbols:
I is 1
V is 5
X is 10
L is 50
C is 100
D is 500
M is 1,000

_
V is 5,000 any symbol with a bar on top times 1,000, obsolete since the largest numbers usually expressed in Roman system are dates.

Rules:
I. There is no symbol for zero;
II. The number is calculated from right to left.
III. If the symbol on the left is larger or equal than the consecutive right symbol, the symbol on the left is adding to the number. For instance, larger: VI is 5+1=6, equal II is 1+1=2, combination VII is 5+(1+1)=7;
IV. If the symbol on the left is smaller than the consecutive right symbol, the symbol on the left is substracted from the number. For instance, IV is -1+5=4, XIV is 10+(-1+5)=14;
V. Every kind of symbol is substracted at most once if is ever substracted. For instance, if we want to note 18, we us e XVIII rather than IXIX;
VI. The code should be as short as possible. For instance, we use IV to note 4 rather than IIII;
VII. The smaller symbol should be on the rightmost possible position. For instance, 39 is X_X_XIX but XIX_X_X, 14 is XIV but VIX;
VIII. There is no two consecutive substractions. For instance, 1989 is MCMLX_X_ XIX rather than MCMIXM

Samples: this year 2005 is MMV, 1979 is MCMLX_XIX, 1989 is MCMLX_X_XIX.