6 kyu
Roman Numerals Decoder
15,748 of 50,877jhoffner
Loading description...
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Nice Kata! Took some time to understand it. If you are trying to solve it, do checkout the given wikipedia link.
This comment has been hidden.
Your solution has two problems:
"CMIX"
, which should be 909.Your solution has some bugs to fix, it's not a kata issue.
THIS IS NOT A 6 KYU🔥🔥🔥🗣️🗣️😡🤯
Had Error: IndentationError - Unexpected indentation in solution.py at line 3 while defining the roman_numerals dictionary. how I solved it Solution: The error was resolved by fixing the indentation in the code, ensuring that it aligns correctly with the rest of the code
python new test frame work is missing.
done
I enjoyed this one. Thanks!
Like it!
This comment has been hidden.
This is not a kata issue. You need to check the way that you're adding to the total. For every 'I' character, you add one. This is good for something like "III", but in roman numerals, the number four is written as "IV". So, where your code sees it as 6, (1 + 5), this is actually 4. For your code to work, you need to add some kind of conditional check that sees if this 'I' is part of an 'IV' or is just an 'I'
Same issue with the roman number MDXLIV. This is M (1000) + D (500) + XL (40) + IV (4).
Ah, thank you.
It´s easier if you use "if" to validate the occasions when you need to subtract
zipWithNext is the go to with this one for sure :)
This comment has been hidden.
Yes, I have successfully finised it on my way in c++.
bro made sure to make the most un-understandable problem detailing to the most easiest problem , just give us the values of I and V and M and C and X
Thank you. But can you add more tests, because it don't cover all options?
I've revised a Rust translation for this kata addressing the issues pointed out in the original translation.
Please review and suggest changes or approve if appropriate.
approved.
This comment has been hidden.
This comment has been hidden.
Hints aren't kata suggestions. Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
pretty tricky one!
Java translation
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#works-but-no and try calling your function in your IDE several times in a row, it'll fail there too. Not a kata issue.
Thanks! Now I see a problem)
This comment has been hidden.
God, I did it! The most important thing to consider is that if XL occurs in a line, that is, X(10) < L(50), then it is imperative to subtract the smaller L(50) - X(10) = XL(40) from the larger one. And so with all Roman numerals.
Hi,
Ok, last warning. Either you stop this or your account gets locked.
Cheers
I'm so sad to find out .maxReplacements cannot be used in Swift due to old API maybe?
This comment has been hidden.
Follow the link in the description, your code fails the test with IV -> 4. Also, read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
Dart Translation waiting for approval.
Isn't this a duplicate of this kata by the same author as well?
Interesting that the one you linked is 2 steps higher even though it is essentially the same thing. Is reverse egineering this one that hard...
This kata doesn't provide all the necessary information required to adequately complete the 100 or so final test cases. Certain roman numeral combinations aren't provided and should be if they're going to be included in the final tests. Additionally, the testing system appears to be knocking numbers off of my results even though console prints show correct solutions
Hi - your solution doesn't work with the very first example given in the description:
That's a good starting point to debug your approach, to make sure you understand the kind of subtle requirements of a correct decoding approach.
If you are encountering Roman numerals for the first time, like many people who studied this kata, you might have to do some research on the specific rules if you are not familiar with them - for example in the above example, the
CM
adds900
to the result etc.Here's the thing though the purpose of this site is to learn coding not roman numerals. Therefore all information outside of coding necessary for completion of the kata should be included in the description.
Additionally applicable variations should be present in the initial test results rather than the final test results since the kata description is lacking and the final test results cant be viewed.
While i appreciate the comment the failure is largely on the creator of the kata
That's not how it works. You should learn on your own, and here your knowledge is tested. You can learn here seeing other's solutions and sometimes very basic things are spelled out for you, but normally it's just the testing part.
@tgutmann87 - Just to comment about the "final test results can't be viewed" thing: you can always in any kata print the input: you can learn how to do this here in detail:
https://docs.codewars.com/training/troubleshooting/#error-messages-and-printing-your-inputoutput
or, since you're working in Python, I can briefly explain as follows:
This will allow you to see which inputs your current solution is failing on (you will see them in the console output above the failed test messages).
Again not helpful and doesnt address the core of the issue that all required information to complete the coding is not present.
And again, that's a misconception you have. Katas which involve letters won't tell you what a letter is, the same with katas that involve maths. You should do some research on your own sometimes. Anyways, I've added a link to the relevant Wikipedia page so you can read it from there.
I'd say it does provide all the info it needs when it says assume the roman numerals will always be valid inputs. So you have to make a solution that handles every possible combination of roman numerals - and as already mentioned you probably will have to research sometimes to learn the ins and outs of a topic that you are not necessarily knowledgeable in when coding e.g. if you were doing game programming you may need to do some research on physics formulas depending on what you are trying to do.
Cound someone pass my common lisp translation of this kata?
"Roman Numerals Decoder" CommonLisp Translation
Approved by someone.
This comment has been hidden.
This task decribed very confusing and the roman numbers table is not full.
M 1000 CM 900 D 500 CD 400 C 100 XC 90 L 50 XL 40 X 10 IX 9 V 5 IV 4 I 1
what does this error mean?
This comment has been hidden.
There is no ambiguity possible relative to roman numbers (at least with the values tested here). If someone doesn't know, it is easy to find with a single online research. Does a kata involving numbers need to explain what numbers are?
This comment has been hidden.
When one doesn't know or understand something, it's not doing him a favor to give away the solution. Failing, testing and searching is part of the learning process. We are not talking about any ultrasecret concept here: google
I agree there is no point in giving away an answer. Right now though, this kata is just a badly described version of https://leetcode.com/problems/roman-to-integer/.
Currently this Kata describes roman numerals as
"Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost digit and skipping any 0s. So 1990 is rendered "MCMXC" (1000 = M, 900 = CM, 90 = XC) and 2008 is rendered "MMVIII" (2000 = MM, 8 = VIII). The Roman numeral for 1666, "MDCLXVI", uses each letter in descending order."
It is deliberately misleading by describing some numberal pairs while omiting others. I fail to see how having a misleading description is beneficial to users who are trying to learn.
I am simply suggesting changing the above quoted description to include something like (assuming I wrote these correctly:
The number 449 is rendered "CDXLIX" (XL = 40, CD = 400, IX = 9) while the number 4 is simply rendered "IV"
That one sentence makes the scope of the problem much more clear.
This comment has been hidden.
Don't post solutions in Discourse, and use a spoiler flag as soon as you post code somewhere (I put the flag on for you this time).
.
This comment has been hidden.
The break statement inside the inner loop will always be executed after the first iteration because of the else clause, causing the outer loop to also break prematurely. And you don't need nested loop for this solution.
This comment has been hidden.
Please use markdown tags to format your code or it's not usable. Refer to the documentation about this and more: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
Please don't post solutions in Discourse.
roman language is confusing 4 should equal iiii but its actually iv
It's not roman language, it's roman numbers, and that's how they work. Google it if you don't know what it is but please don't raise issues.
This comment has been hidden.
Not a kata issue,
"IV"
is 4, not 6.This comment has been hidden.
i havent analyzed it toroughly but the fact that
counter
andverifyLastNumer
are not reset at every function call is probably problematicI dont know whats wrong, I did a for loop that checks conditions for the Roman letters and would assign the integer += the value of this letter, but for some reason it doesnt work, and I == 1 , V == 5 but in the test case IV is 4...
that's not how roman numbers work. in the case of
IV
,I
(1) is subtracted toV
(5) to give 4 you should search the internet for an article that explains how roman numerals workC translation with random tests
Approved :)
some of accepted solutions do not work. Please add test cases for MCD, XIX for example. Just check https://www.codewars.com/kata/reviews/51b6249c4612257ac0000008/groups/5dbdf3e9df599f0001e24050
I added random tests to JS
This comment has been hidden.
This comment has been hidden.
at the very least, put a spoiler flag on this kind of message...
oops
This comment has been hidden.
Language? For someone to be able to fix this you should provide your code with a spoiler flag. See : https://docs.codewars.com/references/markdown/#code-block
The language is F#, as indicated by the error message. (program.fsx, FS0039)
The problem is that the tests apparently don't open the namespaces requied for them to run. If I place the followng lines at the beginning of my code, it works:
This issue has been pointed out some times ago. A new translation in F# in order to fix this has been provided but has not been approved yet. CodeWars is a collaborative website, that's how it works and this kind of thing can happen.
This comment has been hidden.
Not a kata issue,
"IV"
is4
. Read this and thisThis comment has been hidden.
1347
is'MCCCXLVII'
"LX" it's equal to 50+10= 60 but "XL" equal to 50-10 = 40 as well "DM" equal to 400
DM
isn't a valid roman numeral.CD
is 400.OP solved it, closing
F#:
Run 'Attempt' without modifications you receive this error.
/home/codewarrior/program.fsx(6,17): error FS0039: The value or constructor 'Dictionary' is not defined. Maybe you want one of the following: dict
My solution passed on Test, but on Attempt I'm receiving this error - no matter what code is entered.
It's a translation issue, and if I find time I will try and fix it, but you can get your code to submit by including the following statements at the top of your solution:
I have forked the F# translation to move the three imports above into the preloaded section - this should hopefully prevent the issue from affecting anyone else once approved
If kata author / PU could take a look please - https://www.codewars.com/kumite/6048f970a75f17000b8665e0?sel=60cc53d5382b90002b1ac44e
approved, the issue seems indeed solved
can we have the random tests please?
Already raised as issue ~~
Kotlin translation waiting for approval
Approved
In the somewhat common, more readable/production acceptable JS solution, all solutions seem to use split. But since we are trying to access the individual characters in the given string, we can just access these characters by doing
stringTypedRoma[i]
. Is there something wrong with doing that?Some solvers did not know they can iterate over a string, some think arrays provide a clearer illustration on how each sub-element should be processed...
This comment has been hidden.
Already raised as issue
I can't submit my solution. Even though my code passed all the tests i get an exit code (1); Here is the error: STDERR UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x03e800000032 (pc 0x000000426a30 bp 0x000000000000 sp 0x7fff7ba3dbd0 T1) ==1==The signal is caused by a READ memory access. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x426a2f (/workspace/test+0x426a2f) #1 0x7f47f0b180f0 (/lib/x86_64-linux-gnu/libc.so.6+0x430f0) #2 0x7f47f0b181e9 (/lib/x86_64-linux-gnu/libc.so.6+0x431e9) #3 0x7f47f0af6b9d (/lib/x86_64-linux-gnu/libc.so.6+0x21b9d) #4 0x4050e9 (/workspace/test+0x4050e9)
UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#c-error-undefinedbehaviorsanitizer-segv-on-unknown-address-0x000000000000
Thank you.
This comment has been hidden.
not a suggestion.
sorry please
Please, add the following test case into the test cases Test.assertEquals(solution('XLIV', 44)
now this case is not tested when we have two numbers or "parts" that should be carefully avoided, some of the provided solutions don't take it into account.
I second this. I accidentally got the right answer, then I immediately realised the test cases didn't handle cases where two or more parts should be minused.
Rust translation
Approved by someone
Test #5 is wrong. How to report about this mistake?
Test.assertEquals(solution('XXI'), 21) Test.assertEquals(solution('I'), 1) Test.assertEquals(solution('IV'), 4) Test.assertEquals(solution('MMVIII'), 2008) Test.assertEquals(solution('MMVIII'), 1666)
Language?
There is no such test in javascript, click reset to refresh the sample tests. Copy your code before doing that and paste it again after.
Or simply change it to this:
Test.assertEquals(solution('MDCLXVI'), 1666)
This comment has been hidden.
This comment has been hidden.
T3NTACLE, please don't post solutions in Discourse, it's not for that. And if you find a solution interesting, post your comment in that solution (there is a Solutions section for that).
I flagged it with spoiler
Yes, but even then, there are some problems with that:
So let's keep things tidy ;)
ok ,sorry i didnt know
It was not marked as a spoiler until a moment ago when I marked it.
Tests are expecting Test.assertEquals(solution('IV'), 4). IV should equal 6.
no.
IV
is 4, not 6.how that is the most confusing to me, if I is one V is 5 how does it subtract
This comment has been hidden.
This comment has been hidden.
Those aren't valid Roman numerals, so no.
I was bad at reading wikipedia it seems like, thx for the fast reply!
Awesome Kata! Made me use my Grey Cells hahahhah;)
Great kata, thank you!
I had trouble with the randomized tests. Something in the test kept subtracting 200 or 20 from my answer, I managed to pass all 105 tests by luck though.
Elixir tests are broken on attempt. They always substract 200 or 20 from my sum and then compares that to the expected number. If I do IO.puts(sum) right before returning the sum - the sum being printed in console and the expected one matches all the time. The tests are broken, pls fix.
There was an error with the tests but not one related to your code. The test function had the
expected
and thebut got
feedback messages reversed; I've fixed it now so you should get the correct feedback. You will still need to correct your solution to pass.This comment has been hidden.
Already raised as issue
HASKELL:
In order to prevent people faking a solution by writing a tricky Num instance, proposed tests must change. This modified specs will do the thing:
Current tests are:
This comment has been hidden.
Tests are fine.
If you post an issue, at least give some information such as the language you are using.
han
wrong solutions
This comment has been hidden.
Which language? What input/expected value? What do you think it should return instead?
I think this exercise should had more test cases in order for it to be correctly tested.
Very old and deprecated Swift API, unable to complete kata with modern Swift documentation. Updating kata to Swift 5 would be very great.
Enabled Swift 5.
Thanks a lot!
can't post my solution, so..
Edge cases are missing in most languages, e.g
XIV
andXIX
. Solution that handles them incorrectly can still pass all the tests.In Ruby, the only edge case I had to handle was IV.
Most languages do not have random tests.
This was very challenging... I'm sure that my answer wasn't best practice but i'm happy I worked through the problem and passed the kata!!!
This comment has been hidden.
This comment has been hidden.
I can't seem to print to the console? Tests are working though.
This comment has been hidden.
... 8-o I don't know what you're tying to do but hey, I'll try a somewhat safe bet:
CW works differently of some other website. Here you have to actually
return
your result, not anything else.BTW, note that with
3,191 of 11,437
completions in python, the odds that you actually found an issue (meaning, a problem in the kata itself, and not in your own code) are... well, extremly thin... ;)There is no sample test in the Kata.
oh, that... yeah, very old kata... :/
This comment has been hidden.
if (!function_exists('convert')) - help me, problem is solved.
Could someone please add a sample test in Haskell? Or how could I do that?
More tests would be good. Some of the Typescript solutions are truly awful. More tests would root them out. Good puzzle though :)
Already raised as issue
Need some more tests on the thing. It doesn't test all edge cases. For example there aren't any situations where you need to deal with 'XL' or 'CM'. Also a test where you check if a 'roman' input is indeed valid like IIX would probably help make more robust algorithms.
Test case for javascript is missing. Cannot complete the kata.
Either create your own sample tests or click Attempt directly.
I've added some sample tests to the JavaScript version.
This comment has been hidden.
Not an issue.
This comment has been hidden.
Not an issue.
Need better and/or more test cases on this Kata as code is being accepted but gives wrong output in certain edge cases
I don't see an option to submit my solution.
restore down your browser window
a hardcoded solution for an improperly built Kata.
I suggest providing tests and allowing console output to round off this Kata.
Already raised as issue
add more tests and random tests
Already raised as issue
This comment has been hidden.
That's a question, not an issue. Don't post code without marking your post as having spoiler content. Read about javascript testing framework here
yes ,i see ,thanks
It says XL should match 40, which is wrong. XL is converted to 60 , not 40. Due to this fault i can not submit my code which is working correctly.
No.
What is the numerical value of
IV
?4
Right. So why
XL
should be 60?Got your Point. Thanks.
It should have a definition of 'Roman Numeral'. 'IIX' or 'IC' can be valid Roman numeral depending on definition, but it's not handeled in the test case or solutions.
Suggest adding these default test cases for Python:
Lua translation Kumited - please review and approve
This comment has been hidden.
Works when I try it. Maybe try to submit again.
Thanks mate the problem is usualy using Run Simple Test button before confirm and this time return error !! but when submite it done .
should I return somthing if the user input not correct ?
This comment has been hidden.
This comment has been hidden.
I'd suggest including more test cases, I'm not convinced my solution would have worked in exhaustive tests.
Already raised as issue
Is it just me or is this kata a little easy for a 4 kyu?
This comment has been hidden.
This isn't correct. I tested an in complete answer and passed all the tests.
This is either simplified or the tests aren't complete. I submitted a solution that accepts translations like 'IIX' and translates them to '10' which should rather raise an Exception because it's not a valid roman numeral.
The instructions say it takes a Roman numeral (so we can assume it's a valid one). There are katas with input validation but they're still in beta: http://www.codewars.com/kata/roman-numerals-converter-and-validator http://www.codewars.com/kata/roman-numeral-decoder-with-format-validator
Could you add a link to some page where the roman numerals are fully explained? I had a couple of doubts... so many years since I was taught this at school... x_x
Go translation added.
Elixir Translation added.
R translation kumited.
Solution is described in comments at the very end of the test cases (test cases generate a random natural number in a valid range, convert it to a roman numeral using the inverse function from your other roman numeral kata, and then check that the solution generates the original number, so a reference solution isn't needed for the tests, but I added it at the end in case you're not familiar with R). Wasn't that a great run-on parenthetical phrase?
Your solution like all the ones I see is flawed. For example, you accept "XXIC", which is not a correct roman number. Only regex can save you in this case.
From the description:
So you make a good point, but the fact that an invalid input is accepted is not a flaw for this particular task. Maybe you should create a kata for 'validate a roman numeral'?
oh and thanks for approving the translation, @jhoffner!
Missed your point in the description. Suggestion accepted ! I'll work on it. It would be my first one. I think it would deserve a 3kyu grade. What do you think?
it depends on how you structure it. this kata was rated quite a while ago, though, so i wouldn't use its rating as a benchmark. kata tend to be rated lower now.
Why on earth did I LOSE more than 1000 honor after solving this?!
This is likely due to a site problem rather than a problem with the Kata itself - please raise an Issue Report on the official Codewars GitHub repo.
Thank you for your reply! It was probably a bug, after I did another Kata I got all the points back.
C++ Translation Kumited - please carefully review and approve :D
Your solution like all the ones I see is flawed. For example, you accept "XXIC", which is not a correct roman number. Only regex can save you in this case.
Gimmicky for a 4th Kyu... Its more about knowing how to read roman numerals than programming skill.
Shouldn't this be ranked much lower?
If your solution accepts something like "XXIC", you did not really code the solution but only the minimum to pass the tests. If you really solved this kind of issue, you know it deserves its grade. The real pain is that not enough tests are provided to assess the grammatical comprehension of the solutions.
exactly, hence it literally is dependant on whether the coder knows how to read roman numerals. The difficulty in algorithm is rather lacking. If anything, I would say the only tags that fit this kata are Parsing and Strings.
Haskell test cases not working o not implemented:
Example tests is empty, but the actual tests are there.
Tests for JavaScript are not written.
That's not too much of an issue.
TDD is not complete for this assignment. Here is what I used for TDD (tests are taken from Instuctions of this assignment). Replace blank rspec with this one:
describe "Solution" do Test.assert_equals(solution("XXI"), 21) Test.assert_equals(solution("MCMXC"), 1990) Test.assert_equals(solution("MMVIII"), 2008) Test.assert_equals(solution("MDCLXVI"), 1666) end
if these four work for you, your kata answer should be correct.
It's recommended to fill in the exmaple tests but are not mandatory, and since only a few tests is already mostly sufficient to test for correctness it's not that much of an issue.
Thanks for the sample test. This one helped me work it out. Greatly appreciated :)
test says: Response received but no data was written to STDOUT or STDERR. what does this mean?
my function ends with "return decimal" in case of any doubt it would at LEAST return 0
There are no example testcases so nothing is running. Run the fixed testcases instead by clicking the "Attempt" button.
You should have the translation for all roman numerals in the question
This comment has been hidden.
Python:
There are no tests defined for Python
I think this was done on purpose. What is realy missing is a link to the Encoder-Kata, because only there a lot of relevant information for roman coding is presented.
Agree with some of the other codewarriors here in that this was way too easy for 4 kyu. There are no test cases for Python, not sure if this was intentional or not.
IMHO this is too easy for a 4kyu problem. I'd rather rate it 6kyu.
Cannot be changed
I was able to submit the final solution (Haskell) by hardcoding 5 values. This kata definitely needs more verifications such as random test cases.
Re-raised this issue because lots of languages do not have random tests.
Needs more tests just like: IV, IX, CXIX...
Agreed and also going in the high numbers - I had errors initially in my code that the test didn't catch.
I too submitted a solution that didn't work for irregular subtractive expressions (such as "MCDXLIII").
Too easy for 4 kyu. Also needs more test cases.
Already raised as issue (reranked to 6kyu some time ago)
No test cases for Python 3.4.3
Haskell
I can't submit my solution :( That is a little bit annoying. I am glad I haven't spent more than ten minutes on this. Still, why is this flagged for Haskell if there is no test for it?
Example tests is empty, but the actual tests are there.
Nice. Thank you.
This kata is too easy for 4 kyu. I have had 6 kyu problems that were much more challenging.
Shouldn't be 4 kyu, more like 6.
I agree. This exercise seemed much easier than other 4kyu kata.
I also agree. It use to be hard for me to do a 5 kyu, or even 6 kyu, and this seemed very easy to me.
Ranking cannot be changed (anymore)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Language?
[Haskell]
Is there any test case for haskell? I spent a lot of time solving this kata (and I did it). But I was disapointed when found out that tests are missed.
I've added a translation to C#. Please check and approve. :)
Top rated algos are more complicated than needed...
I'm surprised as to how the top rated is... well... the top rated.
Please check out my algo for a much cleaner and KISS implemented algo, and rate if you can.
Roman Numerals Decode KISS algo
Thanks
The testcases could check for malformed values. It would be an extra challenge.
Hello,
This kata is duplicit with: http://www.codewars.com/kata/51b66044bce5799a7f000003
Only half-duplicate, really. That one also has you convert to roman numerals. Though there is a separate kata for that as well.
When I try to submit I keep getting "Failed to construct test fixture properly. Did you provide test cases?" Any idea why this is happening?
For Some reason this also occurs when I add
Test.assert_equals(solution("MCMXC"),1990)
to my tests. All other tests work fine but as soon as I add this test I get the same error.My solution seems to work for all of my tests and I would really like to submit it as I love seeing other peoples solutions but I don't want to forfeit which is currently my only option.
Please resolve this.
This comment has been hidden.
For the CoffeeScript version, I'm getting the following error before getting into the function:
TypeError: number is not a function
EDIT: Whoops, messed up on my side. NVM
Mine originally passed, though when I wanted to check my work, and the output for roman="MCDXLIV" gave an incorrect value. I've fixed it (even though I passed the first time), but you might want to be more thorough with your checks.
You ought to include multiple subtractive expressions -- which allowed me to originally pass with an incorrect algorithm (e.g. MCDXLIV), irregular subtractive expressions (e.g. MCCDXXLIIV), irregular additive expressions (e.g. MMMMDDDD), etc.
Edit: Did some more research on Roman Numerals.
Unfortunately this Kata currently doesn't validate to all fully normalized subtractive expressions.
on 3.: That can't be true to "M"/"D", and "X"/"V", the higher numerals happen to be half of the other. So DM would equal D, VX would equal X, this is redunant, and there is no cleaner way to represent 900 as CM, where M is not the next highest value to C. I think less numerals win on the same amount (VX vs. V)
You're correct from what I can find today. I don't know what I was thinking when I wrote this; it was a while ago, but at first glance it seems like a typo because IX is obviously valid subtractive notation. According to this StackExchange post, the convention is that I is valid to subtract from V or X, X from L or C, and C from D or M.
I'm very surprised to see that my solution is simpler and cleaner than the top rated solutions for this problem.
Cool! How does it work? I can't quite get my head around it... Some comments would be nice; I'd be interested in understanding it better.
It's no secret that subtractive notation is the part people struggle with. It's fairly easy to account for. Most people have done that the long way rather than the short way. I also can't wrap my head around why anyone would use regular expressions for this problem.
And of course now I realize that it's technically invalid and still passed.
Edit: And now, fixed.
Would have been nie to have a quick run down of all the numeral values, or at least the numerals used.
I was very confused that we didn't have to parse "VL" as 45. "VL" should read "5 away from 50", however, here it means "5 and 50".
Not really. VL isn't a proper roman numeral. XLV is the proper roman numeral for 45.
See, that might have been where I was confused :) It makes sense, thanks.
This comment has been hidden.
This comment has been hidden.
well, if it's anything like the 2nd most voted solution, then RESPECT! That's an awesome solution I was too lazy to look for! An I take back the "lot of work for little pay" statement!
This comment has been hidden.
looks like eval() doesn't work in here...