# Project Euler #89: Roman numerals

# Project Euler #89: Roman numerals

Vishu26 + 0 comments I passed the first test case and the program is giving correct results for custom inputs. But it is giving runtime error for other test cases..

efreet + 0 comments This Hacker Rank question looks similar to the original Project Euler question, but it's actually quite different.

For the start, Project Euler only requires you "count" the character differences, while Hacker Rank requires you to actually convert to the short form. More problematic difference is that their inputs follow different rules. All of Project Euler inputs are still "valid": e.g. only one 'V' can appear in a string.

I ended up having two different solutions for these questions. I had a solution passing all tests in Hacker Rank, but failing Project Euler.

kitchent + 1 comment Is there any clean approach without first calculating the value in decimal form? I've passed every test cases of this problem, but I hated it. For the original problem, I used a

`dict`

to count the number of consecutive occurrences, and increment`total += 3`

or`+= 2`

accordingly. But it seems this approach is not suitable for the HackerRank version, where there could be invalid input like`VVVVVVVVV`

.xie1995 + 0 comments Yes. It can be done by a series of string replace.

Perhaps it's easiest to first consider how

`I`

`II`

...`IIIIIIIIIIIIIIIIII`

`IIIIIIIIIIIIIIIIIIII`

can be converted to`I`

`II`

...`XIX`

`XX`

by a series of replacement rules. Since the relationships between`IVX`

`XLC`

`CDM`

are the same, they can be governed by similar sets of rules.

Er_aditya + 1 comment **I solved this question 100% all test cases cleared.**But I want to know what**all other approach**can be used for this problem, I used HashMap to put all key values and printed them using Reminder and Modulas Strategy.for eg 71 will be LXXI

map.put(1,"I"); map.put(10,"X"); map.put(70,"LXX");

and so on..

Crafter_Artisan + 0 comments Pretty much the same, except I used a dictionary and three string arrays -- one for each of the rightmost three digit places -- instead of a hash map.

thigwyd + 1 comment Can we be sure that the test cases are valid? For example, they don't include something like "IIIVII" (which is ambiguous) or "IM" (which is not syntactic)?

kermitthefrog_jc + 0 comments It says that all the test cases are in descending order.

opeispo + 2 comments Any special test cases to note? I used this same code with the Project Euler question and got the correct answer.

logeshrajagopal + 0 comments can i get some sample test case??.. fr dis #89

angusmacdonald + 1 comment I was failing all but the first test case until I realized that I wasn't accounting for the example case given in the description (IM should be CMXCIX) -- for that case you need to remember I can be subtracted from 10 as well as 5.

bytebx1212 + 0 comments did you pass all the test cases??

abhishek9560 + 1 comment how can i see other test cases ???

Shimo_Singh + 0 comments You can't see other test cases for contests.

BinaryTrance + 0 comments 1519 is a pretty good test case :P

No more comments

Sort 8 Discussions, By:

Please Login in order to post a comment