13
0
Your task is to convert a given positive integer from Arabic numeral to Roman numeral.
Things get difficult when you count to 4000.
The romans did this by adding a line above a symbol to multiply that symbol by 1 000
. However, overlines aren't exactly displayable in ASCII. Also, there are double overlines to multiply a symbol by 1 000 000
, and then triple overline to multiply a symbol by 1 000 000 000
, etc...
Therefore, I decided to use parentheses to replace overlines.
The symbols can be individually placed in parentheses. For example, both (VI)
and (V)(I)
are valid representations of 6 000
. (V)M
is also a valid representation of 6000.
(I)
is a valid way to represent 1 000
.
Testcases
Input: 1
Output: I
Input: 2
Output: II
Input: 3
Output: III
Input: 4
Output: IV
Input: 15
Output: XV
Input: 40
Output: XL
Input: 60
Output: LX
Input: 67
Output: LXVII
Input: 400
Output: CD
Input: 666
Output: DCLXVI
Input: 3000
Output: MMM
Input: 3999
Output: MMMCMXCIX
Input: 4000
Output: M(V)
Input: 4999
Output: M(V)CMXCIX
Input: 6000
Output: (VI)
Input: 6000000
Output: ((VI))
Input: 6006000
Output: ((VI)VI)
Input: 6666666666
Output: (((VI)DCLXVI)DCLXVI)DCLXVI
Scoring
This is code-golf. Shortest code in bytes win.
1The justification for why this isn't a duplicate clutters the spec. It would be better without it IMO. – Mego – 2016-04-17T05:51:04.630
Where would I add the justification? – Leaky Nun – 2016-04-17T05:51:59.077
1Leave it out. If someone questions whether or not it is a duplicate, have the discussion in comments or in chat. – Mego – 2016-04-17T05:52:35.700
@Mego Done. :-) – Leaky Nun – 2016-04-17T05:53:03.847
Is
(IV)
an acceptable representation of 4000? – Neil – 2016-04-17T09:52:02.090Yes, clarified. – Leaky Nun – 2016-04-17T10:07:05.743
@Neil For that case, you can output which one you want, 'cause
(IV)
andMMMM
are the same length in bytes. – Erik the Outgolfer – 2016-04-18T10:16:48.323@ErikKonstantopoulos Not really.
MMMM
is not accepted. – Leaky Nun – 2016-04-18T12:41:42.223Possible duplicate of Roman numeral converter function
– mbomb007 – 2016-04-19T19:22:55.210@mbomb007 That's the opposite direction. – Martin Ender – 2016-04-19T19:46:00.370