Challenge
###Challenge
GivenGiven some input string, return a truthy value if it represents a correct roman numeral between 1 (=I
) and 3999 (=MMMCMXCIX
), and a falsey value otherwise.
###Details
Details
- The input is a non-empty string that only comprises the characters
IVXLCDM
. - The roman numerals (that we use here in this challenge) are defined as follows:
We use only following symbols:
Symbol I V X L C D M
Value 1 5 10 50 100 500 1000
To define which strings are actually valid roman numerals, it is probably easiest to provide the rule of conversation: To write a decimal number a3 a2 a1 a0
(where each ai
represents one digit. So for example to represent 792
we have a3=0, a2=7, a1=9, a0=2
.) as a roman numeral, we decompose it into the power of tens. The different powers of ten can be written as follows:
1-9: I, II, III, IV, V, VI, VII, VIII, IX
10-90: X, XX, XXX, XL, L, LX, LXX, LXXX, XC
100-900: C, CC, CCC, CD, D, DC, DCC, DCCC, CM
1000-3000: M, MM, MMM
Beginning at the left side with the most significant digit of the, we can convert the number that each digit represents separately and concatenate them. So for the example from above this would look like so:
Digit a3 a2 a1 a0
Decimal 0 7 9 2
Roman DCC XC II
Therefore the roman numeral for 792
is DCCXCII
. Here is a full list of all roman numerals that are relevant for this challenge: OEIS a006968.txt
Examples
###Examples Truthy
MCCXXXIV (1234)
CMLXXXVIII (988)
DXIV (514)
CI (101)
Falsey
MMIXVIII
IVX
IXV
MMMM
XXXVX
IVI
VIV