6 kyu

Roman Numerals Encoder

16,026 of 56,641jhoffner
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • gaogao-qwq Avatar

    There is an issue in Haskell's sample test (L16)

    module RomanNumeralsSpec where
    import Test.Hspec
    import RomanNumerals (solution)
    
    spec :: Spec
    spec = do
      describe "Some tests" $ do
        it "should translate 1 to I" $ solution 1 `shouldBe` "I"
        it "should translate 4 to IV" $ solution 4 `shouldBe` "IV"
        it "should translate 6 to VI" $ solution 6 `shouldBe` "VI"
        it "should translate 14 to XIV" $ solution 14 `shouldBe` "XIV"
        it "should translate 21 to XXI" $ solution 21 `shouldBe` "XXI"
        it "should translate 89 to LXXXIX" $ solution 89 `shouldBe` "LXXXIX"
        it "should translate 91 to XCI" $ solution 91 `shouldBe` "XCI"
        it "should translate 984 to CMLXXXIV" $ solution 984 `shouldBe` "CMLXXXIV"
        it "should translate 1000 to M" $ solution 1889 `shouldBe` "MDCCCLXXXIX" -- issue here
        it "should translate 1889 to MDCCCLXXXIX" $ solution 1889 `shouldBe` "MDCCCLXXXIX"
        it "should translate 1989 to MCMLXXXIX" $ solution 1989 `shouldBe` "MCMLXXXIX"
    
  • sukima Avatar

    This comment has been hidden.

  • eymeter Avatar

    it was extremely difficult for a haskell beginner >:(, did it tho.

  • danik00111 Avatar

    My solutiom is what I consider to be the most hilarious code I ever wrote. It is 2 years old. And the funniest part about it, is that it gets the job done flawlessly...

  • mhaatha Avatar

    this test makes me realize i'm so dumb af

  • Garald_48rus Avatar

    Test Results: Kata Fixed_Test Random_Test Expected: equal to "MDCCXL" Actual: "MDCCХL" why didn't the test pass?

  • trashy_incel Avatar

    C fork

    • making description language-agnostic
    • it is explained what kind of pointer to return
    • better assertion messages
  • neweber Avatar

    With Ruby, MRI 3.0.0, all random tests are failing with the error

    ./spec/solution_spec.rb:23:in `block (4 levels) in <top (required)>': undefined method `roman' for RSpec::ExampleGroups::RomanNumeralsEncoder::RandomTests:Class (NoMethodError)
    

    All basic tests are passing.

  • RobWeekes Avatar

    My javascript solution is working in VS Code, also works in browser console. (First I used split method to break roman numerals into an array of strings).

    When clicking 'Test' here I get this error: "TypeError: roman.split is not a function"

  • Xros22 Avatar

    really nicely calibrated

  • ch1nya  Avatar

    This comment has been hidden.

  • matahontas Avatar

    Compiler is not working properly when writing in Swift.

  • Non-American Avatar

    Это была очень интересная задача, которую я смог решить!

  • trey_jenkins Avatar

    Currently getting a pass on all normal Ruby tests, but keep failing random random tests. I idependently test the failed random tests and get the currect response every time, and when I run again to submit, I fail between 1-6 other random tests (passing the ones that failed on the previous run). Could this be an issue with the current tests in Ruby?

    /runner/frameworks/ruby/cw-2.rb:60:in block in describe': Expected: "MCMXCIII", instead got: "MXMIII" (Test::Error) from /runner/frameworks/ruby/cw-2.rb:46:in measure' from /runner/frameworks/ruby/cw-2.rb:51:in describe' from /runner/frameworks/ruby/cw-2.rb:202:in describe' from main.rb:47:in `

    '

  • AtayevDmitriy Avatar

    Traceback (most recent call last): File "/workspace/default/tests.py", line 1, in from solution import solution ImportError: cannot import name 'solution' from 'solution' (/workspace/default/solution.py) What should I do with this error?

  • GreeneyedNerd Avatar

    I created a solution that is working in another site that lets me test (https://pythontutor.com/visualize.html#mode=edit) a really useful website that lets you see what your code is doing step by step.

    But I'm getting this reference error and don't know what it means. Usually it will say "expected 3 to be III" or something like that so I can find and resolve the issue, but I've not clue what is happening here. Help would be appreciated.

    ReferenceError: solution is not defined at Context. (test.js:25:12) at process.processImmediate (node:internal/timers:471:21)

  • ozair_ayaz Avatar

    There seems to be some issue with the test cases. I tested my solution earlier and it passed all test cases successfully. But I didn't submit it because I wanted to improve my code. I ended up submitting the same solution (after a couple of day or a week maybe) because I wasn't able to improve my code. But that exact solution is not passing some test cases now.

    I'm using JavaScript by the way.

  • dmytropavlov Avatar

    Is this 6kuy kata?

  • pabloparma1982 Avatar

    I'm doing it in JavaScript. It works as expected outside the page, but when I try to pass it here I get a message like this:

      " should handle small numbers
        2 should return "II": expected 'III' to equal 'II'
        Completed in 2ms
        should handle large numbers
        1000 should return "M": expected 'IIIM' to equal 'M'
        random tests
        687 should return "DCLXXXVII": expected 'IIIM' to equal 'DCLXXXVII' "
        
    

    Any ideas? Thanks.

  • FlorianJSa Avatar

    Seems like that there is an issue with the testcases?

  • jackboccuzzi Avatar

    As a suggestion, I recommend added the other cases, in between 1-1000, to the variable you set up to store the roman numeral symbol and its value. (for example, add 4, 9, 40, etc.)

    Once I did this, it became a lot easier to code out what I wanted to do so I did not have to have a lot of non-sense code trying to replace symbols.

  • Mouthieu Avatar

    Hello everyone,

    I'm coding on python and I noticed a big mistake in the kata. I was trying to make the kata and I was pretty confident about how my code would work.

    After veryfing my code in the website, it says that my code is wrong and give me some numbers that my code return and what they should return instead.

    However, I can tell that the verifying code is wrong because it says that we can't have 3 consecutive letters that are the same which is true.

    But when the veryfing code tell me that 89 that is 'XXCIX' is supposed to be 'LXXXIX' we easily see that the mistake in the verifying code is about how they write the number 8, 80 or 800.

    Sorry for my bad english and I hope it will help some people.

  • jonjames1986 Avatar

    This comment has been hidden.

  • yu5uy Avatar

    This comment has been hidden.

  • pmngl Avatar

    Am I just in the unknown or do all these solution cheat the test system of the kata?

  • LegendaryFartMaster Avatar

    Isn't this a duplicate of this kata by the same author as well?

  • KayleighWasTaken Avatar
  • transan Avatar

    Although, my code is longer than the others, it passed.

    Happy coding!

  • KacperKukula Avatar

    In javascript parameter is not correct.

  • CLQUDLESS Avatar

    This comment has been hidden.

  • Ganesh_Arvindh Avatar

    This comment has been hidden.

  • ПавелРАЗ Avatar

    This comment has been hidden.

  • idodav Avatar

    Really liked this Kata. Also I really liked to see how different the solutions are. It was a nice challange. Thanks!

  • mneLen Avatar

    This comment has been hidden.

  • gawatson95 Avatar

    In Swift, can you use extensions? I have an extension on Int in my code. It complies correctly in Xcode, but not on Codewars. Thanks!

  • png Avatar

    This comment has been hidden.

  • JoshuaSimonBloom Avatar

    My JavaScript solution works correctly on my system, when pasting it in here it breaks?

  • akar-0 Avatar
  • volodkaly Avatar

    Hello, please add some numbers like 5005, 6789, 7963, 8143 to the test. Now you can pass the test even with the output 5005→MV but the correct one is 5005→MMMMMV

  • Slabacode Avatar

    This comment has been hidden.

  • Necro-U Avatar

    This comment has been hidden.

  • akar-0 Avatar

    Logs in random test in Haskell are not informative enough: Falsified (after 17 tests): 2488

  • CeldorWoW Avatar

    Hey,

    There is a similar kata to this one, which is ranked 4 kyu, which asks for a harder task to convert back from the roman to the arabic dates. It might be worth adding link to it. Thanks.

  • HuandXu Avatar

    how to deal with those questions,which it seems so many forks need to write,i may write 10 if to deal with the case,when i see that bro finish it with a great 语句,that impressed me.

  • yannyd Avatar

    This comment has been hidden.

  • user6884205 Avatar

    This comment has been hidden.

  • Gaston V Avatar

    I am trying the F# version. When I click on "Test", everything passes (green). But when I click on "Attempt" I'm getting a couple of warnings about wrong indentation, and an error: /home/codewarrior/program.fsx(42,17): error FS0039: The value or constructor 'Dictionary' is not defined. Maybe you want one of the following: dict

    I am not using a Dictionary in my code. FYI

  • CaptainKoe Avatar

    This comment has been hidden.

  • stellartux Avatar
  • arataca89 Avatar

    This comment has been hidden.

  • jsfelix Avatar

    Why I cannot execute "M".repeat(5)?

  • dshvets1 Avatar

    What do we return if an integer is not in [1,3999] range?

  • Dr2546 Avatar

    This comment has been hidden.

  • BrainHorse Avatar

    Kotlin translation waiting for approval

  • AntMam Avatar

    The numeral cannot be repeated 3 times. What happens if we ever get to the 10,000 years? Current solution returns "MMMMMMMMMM" for the year 10,000.

  • agustin-vaca Avatar

    For Java, the compiler seems to be skipping some operations. I cannot get my functions to work in this environment, but I get the correct answers in an Online Java Compiler and also in Eclipse.

  • lowkeysavage Avatar

    This comment has been hidden.

  • Michael McF Avatar

    Thanks for this. Really enjoyed it. It was tricky to work out intially how to solve it. Loved the many different solution types people had. Great.

  • whatafuckday Avatar

    This comment has been hidden.

  • yogindar-code Avatar

    This comment has been hidden.

  • ferdunt Avatar

    This comment has been hidden.

  • ProgrammingInProgress Avatar

    System says my code failed at 3,4 and 2004.But when I try my code with GCC, it works properly and it yields right values.Test codes are wrong.

  • tspencer9 Avatar

    What's the largest number that will be tested? 3999?

  • rsa Avatar

    Clojure Translation ready for review.

  • user354062 Avatar

    Sql Translation Kumited - please review and approve

  • x10an14 Avatar

    This comment has been hidden.

  • ALT-Browne Avatar

    Surely this is impossible for large numbers because you need to use M more than 3 times in a row unless you do something like MMMDMMMDMMMDMMMD.... which doesn't seem right...

    Am I missinhg something?

  • rajparpani Avatar

    If the entered integer is equal to or greater than the key in the roman numeral map, we deduct the key from the entered integer after the value for that key has been extracted and added to our empty roman variable which is the results. Why do we have to deduct the key from the entered integer? Can someone explain this

  • xxxxxxxxxxdan Avatar

    Help!

    Error: Argument of type '"M"' is not assignable to parameter of type 'void'

    Any pointers? What should I be looking at? TIA

  • srsh-kh Avatar

    This comment has been hidden.

  • Epbrassil Avatar

    This comment has been hidden.

  • alex_rus Avatar

    Hello!I wrote code that passed "TEST" but cannot pass "ATTEMPT". A piece of code appears in the errors that is not in mine. I have screenshots in which everything is clearly visible. Please, help!))

  • valen_millo Avatar

    what is the problem of this code?

  • Tanmoy20 Avatar

    This comment has been hidden.

  • magic990619 Avatar

    This comment has been hidden.

  • magic990619 Avatar

    I passed the test. But fails in random test when attempting. Always fails on one case.

    'The expression (as strings) (actual) == (expected) is false. '

    I am not sure which one is wrong. I want to know that case. Help me.

  • St3fa11 Avatar

    This comment has been hidden.

  • GninninwokyOuattara Avatar

    This comment has been hidden.

  • PhoenixBird Avatar

    This comment has been hidden.

  • 雪域冰龍 Avatar

    I don't understand why it can't be return by StringBuffer.toString(). It just can be return by String. When I return by StringBuffer.toString(), it shows failed with <..[]...>(true) <..[..]...>(false).

  • fibonaccios Avatar

    My code passes with the 3.6 version of python. However, it fails with the 3.4.3 any idea why?

  • lecso2 Avatar

    This comment has been hidden.

  • Kingdra Avatar

    This comment has been hidden.

  • leira Avatar

    C++ random tests, there are numbers larger than 4000, and even negative numbers...

  • JunHill Avatar

    This comment has been hidden.

  • thePETEWguy Avatar

    My test are passed, but I get an "Exit code 139". Why is this?

  • henrywoody Avatar

    This comment has been hidden.

  • msverteczky Avatar

    Hey, first this is a great kata and I enjoy solving it!

    However it would might be better for understanding the purpose of this exercise if the description would contain that the maximum of the input is 3999, with regards to "Remember that there can't be more than 3 identical symbols in a row."

  • lilsweetcaligula Avatar

    This comment has been hidden.

  • happy16 Avatar

    Me aparece que esta mal pero no lo creo yo ya lo probe con mi compilador y le hice barias pruebas y todo correcto. Este es el mensaje de erro en la prueba aleatoria: MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM...CMXXIX Actual: DCCMXXIX

  • konkath Avatar

    Lua translation kummited - please review and approve

  • Slyracoon23 Avatar

    This comment has been hidden.

  • ut3saturn Avatar

    I got the "All tests passed" message but I am not able to submit the code. Help?

  • sfusato Avatar

    Flawed test case in Elixir:

    test Random tests (TestArabicToRoman)
         test/solution_test.exs:81
         Got CDLXX instead of CCCCLXX for n = 470
         code: 1..100 |> Enum.each(fn _ ->
    

    Correct result is CDLXX for 470, NOT CCCCLXX.

  • maudat Avatar

    Hello,

    In the C language, I can confirm that my code returns the right string for 1991 and the tests after, strangely the tests return false The expression (as strings) (solution(1991)) == ("MCMXCI") is false.

    Any idea of the problem here?

  • jgcordel Avatar

    my test Scripts worked fine in my environment, however the simple test cases seemed to fail for solution 4. my result ovbiously return a string "IV", but I received the following error when running through this testing interface: solution(4) should equal to IV expected:I[]V but was:I[I]V.

  • N-Somnia Avatar

    C++, issue with random test:

    Expected: equal to MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM...CXXIX

    678824 'M' total. If I change my code in such a way that the answer can have more than 3 identical symbols then I (obviously) get Execution Timed Out.

  • DrSavinkov Avatar

    Random test calls for negative int values (used std::cerr to see it). If I change an argument as unsigned int, it's no enough memory to write Roman representation. Very sad.

  • yannickjmt Avatar

    Test cases are flawed for numbers between 5000 to 9999 and need a workaround to make them work.

    Either they should be 4999 max, either symbols for 5000 and 10000 should be given (apparently it's a V and X with an overline or vinculum).

  • svenrau Avatar

    In C

    The test cr_assert_str_eq(solution(2843), "MMDCCCXLIII"); fails. But by debugging manually with gcc my code generates exactly this solution. What is wrong? Possibly the test?

    Kind regards

    Sven

  • lucas_l Avatar

    Should either take out the sentence "Remember that there can't be more than 3 identical symbols in a row." or take out examples that go over 3999. Would be helpful to mention how to handle nums over 3999 in description since actual roman numeral systems to express larger numbers do not just spam M until the desired number is reached.

  • LouisMilotte Avatar

    In PHP Rules state no more than 3 identical symbols.

    Failed asserting that two strings are equal. Expected: 'MMMMMMMMMMMMMMMMMMMMMMMMLXXXVIII' Actual : 'MMMMLXXXVIII'

  • Katerls3 Avatar

    In C language: If I add a test cr_assert_str_eq(solution(1992), "MCMXCII"); it passes. However, when I submit, it tells me: The expression (as strings) (solution(1992)) == ("MCMXCII") is false. What's going on?

  • zingo79 Avatar

    The elixir sample tests expect a string result, but when you run the actual solution, it expects a charlist.

  • abrenon Avatar

    In Python, text sent to console using print() don't show up in the Output section.

  • jforster Avatar

    This comment has been hidden.

  • jforster Avatar

    This comment has been hidden.

  • xarxsos Avatar

    I keep getting an error in one of the random tests. Is there a way to know what input number caused that error? So that I can debug my code

  • donaldsebleung Avatar

    C Translation Kumited - please carefully review and approve :D

  • donaldsebleung Avatar

    This comment has been hidden.

  • eliaszica Avatar

    I get this message (2008 should == "MMVIII") but 'MMVIII' is exactly the output of my Ruby solution. All other test cases until this are ok.

  • donaldsebleung Avatar

    Solidity Translation Kumited - please carefully review and approve :D

  • mentalplex Avatar

    R Translation kumited

    Excessively commented reference solution at the top of the test suite :)

  • donaldsebleung Avatar

    This comment has been hidden.

  • donaldsebleung Avatar

    I'm not fluent in Elixir but I'm 99.9% sure that the Elixir translation to this Kata is seriously flawed (I did complete the Elixir version after all in case you're suspecting):

    1. The input 0 is tested as an edge case in both the Sample Tests and the Test Cases although there is no mention of it whatsoever in the Kata Description (or even in 10+ other language versions that I've completed this Kata in). Furthermore, the Roman numerals were not defined for 0 anyway so this "edge case" should NOT be tested at all.
    2. The Sample Test Cases require a string to be returned but the actual Test Cases required a character list to be returned. I actually already had a working solution by the time I clicked "Submit" for the first time but this prevented me from doing so and wasted me at least five to ten minutes trying to figure out.

    If someone fluent in Elixir (or the Elixir translator himself/herself) could go ahead and fix the Issues I mentioned above that would be great. Thanks a lot :D

  • donaldsebleung Avatar

    Codewars Forums - Kata Best Practices - Have Full Code Coverage

    [CoffeeScript] Having only five fixed assertions in total is far from full code coverage and will easily allow logically flawed and/or cheap-cheat solutions to pass. Please (1) either increase the total number of fixed assertions to at least 20 (with edge cases as well) or (2) even better, write 100+ random tests as per standard Codewars practice.

  • donaldsebleung Avatar

    Fun Kata but IMHO a bit overrated; I would personally consider this to be 6 kyu tops.

  • Axure Avatar

    The Haskell template is misleading. It tells us solution :: Int -> String while in the test it actually expects an Integer parameter.

  • kabuboy Avatar

    This comment has been hidden.

  • dangerdak Avatar

    The random test cases in Javascript expect results such as "MMMMMMMMCDLXIII" despite the description claiming that "there can't be more than 3 identical symbols in a row."

  • Groarq Avatar

    There is a minor bug in elixir version of kata. On the first tests (also in the instruction), there is used String type as a result. On the other hand, after "attempting" tests, there is a char. I think it should be corrected :)

  • haugk Avatar

    Haskell

    Ran into the same problem as others:

    /tmp/haskell117115-18-1v1ihj0.ueg2zf47vi/RomanNumerals.hs:5:27:
        Couldn't match expected type `Int' with actual type `Integer'
        In the first argument of solution', namely `s'
        In the expression: solution' s
    

    I was irritated at first. But then discovered it was my bad! I enjoyed it after all.

  • buttonupbub Avatar

    I encountered the same issue as @deadwater. Some of the JavaScript random test cases use input values that exceed the n < 4000 condition. Iterative solutions are not affected by these cases -- "M" is just repeated -- but digit-based solutions are. Marking this as an issue.

  • deadwater Avatar

    When testing the javascript version, it will sometimes pass randoms numbers that actually exceed the parameter condition indicated (n < 4000). That is, I get "expected" answers that look like MMMMMMMMM when they pass something like 8000.

  • anter69 Avatar

    Badly needs random test cases, otherwise it's very simple to hardcode the solution... for a 4 kyu kata.

  • erran-r7 Avatar

    This comment has been hidden.

  • user4912975 Avatar

    This comment has been hidden.

  • rscharfer Avatar

    Just a suggestion - You might put in the details what the upper limit of the argument should be. The roman numeral for 10,000 is an X with a line over it, but I don't think the users need to worry about something that high.

  • DSchwettmann Avatar

    This comment has been hidden.

  • DavidFarago Avatar

    I have just written this kata in C++. Can I somehow contribute my code to this kata, extending it to C++?

  • michib Avatar

    In Typescript, i get the following error when trying to execute my code.

    ../home/codewarrior/spec.ts(1,1): error TS1084: Invalid 'reference' directive syntax. ../home/codewarrior/spec.ts(2,1): error TS1084: Invalid 'reference' directive syntax. STDERR: Error: Command failed: tsc --module commonjs /home/codewarrior/spec.ts

  • jamessouth Avatar

    this was cool but wouldn't it be better if it prohibited memoizing everything except 1,5,10,50,100,500,1000?

  • micnic Avatar

    The javascript version does not have tests to fully test all numbers, I can submit my solution without covering number 5, 100, 10 and many other numbers

  • Helral Avatar

    This comment has been hidden.

  • dinglemouse Avatar

    A single line solution is possible :-)

  • Villen01 Avatar

    Passed all tests, when trying to submit the final solution, I am getting "There was an issue submitting your final solution". However kata appearing as completed, but solutions are not available.

  • michalweiser Avatar

    I'm trying to submit my solution in JavaScript. Tested in jsbin, seems to work well. Submit button rejects it with no message. I'm not even able to see output of my test cases. Am I doing something wrong? Thank you

  • cacr Avatar

    In haskell, I am experiencing some problems when submitting my solution

    /tmp/haskell116317-19-1p9qj5l/Main.hs:28:58: Couldn't match expected type Integer' with actual type Int' In the first argument of abs', namely x' In the first argument of referenceSolution', namely (abs x)' In the second argument of (==)', namely referenceSolution (abs x)'

    My guess is that some test cases are expecting an Integer->String signature when the kata solution has Int->String. Did anybody manage to submit the kata in Haskell ? Shame, it was a fun kata.

  • provector Avatar

    This comment has been hidden.

  • ssendy Avatar

    nice kata...

  • ver0man Avatar

    This comment has been hidden.

  • user1621217 Avatar

    Test should be more exhaustive. I have sseen some aldgorithms in the solutions which would not do the job for numbers like 888.

  • user1621217 Avatar

    In java. The test do not compile. A '}' character is missing.

  • jake-jake-jake Avatar

    This comment has been hidden.

  • ver0man Avatar

    I've translated into Java. Please check and approve. :-D

  • bstenzel Avatar

    I've added a translation to C#. Please check and approve. :)

  • Tearff Avatar

    This comment has been hidden.

  • karakfa Avatar

    same issue with the tests

    /tmp/haskell115119-7-49etmg/Main.hs:28:58: Couldn't match expected type Integer' with actual type Int' In the first argument of abs', namely x' In the first argument of referenceSolution', namely (abs x)' In the second argument of (==)', namely referenceSolution (abs x)'

  • sru Avatar

    In Haskell, the type checking freaks out because the solution has type of Int -> String, but it gets Integer as input for test cases.

    So, the type of solution should be either:

    solution :: Integer -> String

    or more generally:

    solution :: Integral a => a -> String

  • Vaeth Avatar

    You should add what you want returned in the event that number is outside the range of Roman Numerals

  • yomanu Avatar

    This comment has been hidden.

  • Enjeru Avatar

    This comment has been hidden.

  • pixshatterer Avatar

    This comment has been hidden.

  • Kache Avatar

    I don't think the description sufficiently describes how modern Roman numerals are expressed, namely using the following values, listed in increasing order:

    I = 1     X = 10      C = 100     M = 1000
    V = 5     L = 50      D = 500
    

    Numbers are expressed via the sum of additive terms and subtractive terms.

    Additive terms are the addition of terms, listed in decreasing value.
    I, X, C, and M can be repeated up to 3 times in a term, but V, L and D cannot be repeated.

    II = 2
    XV = 15
    CXXIII = 123
    

    When a number calls for a 4th repetition of a value, instead use a subtractive term by following it with one of the two terms larger than it:

    IV = 4
    IX = 9
    XL = 40
    XC = 90
    IIX # No!
    IL # No!
    

    In this manner, all numbers from 1 to 3999 can be represented.

  • Kazeshini178 Avatar

    Should maybe consider added the 1666 test case as I was looking over my solution and I noticed I would of failed if that was one of the test thou I have now fixed it. Might be the case for some other solutions as well.

  • ineiti Avatar

    Yes, me too, but as this is a "valuable" Kata I won't complain - getting higher and higher!

    And even though that I wrote 3 different algorithms, I still don't know what would be the best way to solve the problem, so perhaps a 4th Kata would be great ;)

  • palfvin Avatar

    Is this a duplicate of another kata? I've already done one like this, seen one for the other direction and seen one which includes both directions.