17
4
Input:
An integer.
Output:
- First convert the integer to it's equivalent Roman Numeral.
- Then convert each capital letter of that Roman Numeral to their ASCII/UNICODE decimal value.
- And output the sum of those.
Example:
1991 -> MCMXCI -> 77+67+77+88+67+73 -> 449
^ input ^ output
Roman Numerals:
Here is a perhaps useful Roman Numeral Converter.
Challenge rules:
- Standard Roman Numeral rules are applied, so no alternative forms like
IIII
orVIIII
instead ofIV
andIX
.* - The Macron lines above the Roman Numerals past 1,000 are
¯
(UNICODE nr. 175). So one line counts as+175
and two as+350
. - You are allowed to use any kind of input and output type, as long as it represents the integers.
- The test cases will be in the range of
1 - 2,147,483,647
.
* Roman Numeral rules (quote from Wikipedia):
Numbers are formed by combining symbols and adding the values, so
II
is two (two ones) andXIII
is thirteen (a ten and three ones). Because each numeral has a fixed value rather than representing multiples of ten, one hundred and so on, according to position, there is no need for "place keeping" zeros, as in numbers like 207 or 1066; those numbers are written asCCVII
(two hundreds, a five and two ones) andMLXVI
(a thousand, a fifty, a ten, a five and a one).Symbols are placed from left to right in order of value, starting with the largest. However, in a few specific cases, to avoid four characters being repeated in succession (such as
IIII
orXXXX
), subtractive notation is often used as follows:
I
placed beforeV
orX
indicates one less, so four isIV
(one less than five) and nine isIX
(one less than ten)X
placed beforeL
orC
indicates ten less, so forty isXL
(ten less than fifty) and ninety isXC
(ten less than a hundred)C
placed beforeD
orM
indicates a hundred less, so four hundred isCD
(a hundred less than five hundred) and nine hundred isCM
(a hundred less than a thousand)
For example,MCMIV
is one thousand nine hundred and four, 1904 (M
is a thousand,CM
is nine hundred andIV
is four).Some examples of the modern use of Roman numerals include:
1954 asMCMLIV
; 1990 asMCMXC
; 2014 asMMXIV
SOURCE
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
Test cases:
100 -> 67
1 -> 73
4 -> 159
22 -> 322
5000 -> 261
2016 -> 401
1000000000 -> 427
1991 -> 449
9999 -> 800
1111111111 -> 2344
2147483647 -> 5362
Related – Kevin Cruijssen – 2016-08-01T08:51:58.603
1@martin
9999
->M(X)CMXCIX
->77+263+67+77+88+67+73+88
->800
and2147483647
->((MMCXLV)MMCDLXXX)MMMDCXLVII
->427+427+417+438+426+436 + 252+252+242+243+251+263+263+263 + 77+77+77+68+67+88+76+86+73+73
->5362
. So I've corrected the second, but the9999
was correct. – Kevin Cruijssen – 2016-08-01T09:35:28.6979999. Google says either or. – martin – 2016-08-01T09:51:25.347
1The test case
2222222222
isn't in the given range. Also I agree with5362
. – Neil – 2016-08-01T10:05:49.707@Neil Ah oops, you're completely right. I'll change it to something else. – Kevin Cruijssen – 2016-08-01T10:06:27.233
@martin I'm a bit confused about the
I
with a macron.M
is 1000, so what is(I)
? In the link you gave for9999
it seems to also be 1000.. – Kevin Cruijssen – 2016-08-01T10:18:11.653@KevinCruijssen depending on where you look,
– martin – 2016-08-01T10:24:18.2579000
->IX
+ macron - see here1The title kinda sounds like a Stack Overflow C question. – user6245072 – 2016-08-01T12:02:08.970
3Is the word "fourth" in the title a pun? If not, it should be "forth". – Monty Harder – 2016-08-01T20:47:53.067