Ad
  • Default User Avatar

    Finally it works!
    Thank you for your feedback and for your kata.

    I think my problem where with big integers!

  • Default User Avatar

    Ok!
    Now I pass the -1 to -50 but I fail on the random.

    Thank you I am going to see why!

  • Default User Avatar

    I've changed the tests a bit try now.

  • Default User Avatar

    Ok bkaes!
    I think I am no stuck, I want to know if the value that gives as a solution -45537549124 is -51, like this test:

    Test.assertEquals(lucasnum(-51), -45537549124)
    

    NaMe613, I pass 57 tests before the first fail.

    The test that fails says:

    Expected: -45537549124, instead got: 28143753123
    

    Thank you for your feedback.

  • Default User Avatar

    My apologies for not having replied yet,could you please clarify how many tests you pass before the error occurs.

  • Custom User Avatar

    Please use three backticks to mark code:

    ```
    your code here
    ```
    

    Otherwise it's kind of hard to read your comments. That being said, the JavaScript tests have been changed lately. Did you try again? Also, if you're completely stuck, you can add your current solution as a spoiler in a comment.

  • Default User Avatar

    Thanks for your answer.
    The test that says failed is this one: Test.assertEquals(lucasnum(-51), -45537549124) ?

    -50 to -1
    Expected: -45537549124, instead got: 28143753123
    Which other number can bring me the -45537549124 if is not the -51 ?

    I try with my own test:
    Test.assertEquals(lucasnum(-51), -45537549124)
    And works...

    Thank you for your feedback

  • Custom User Avatar

    Thanks for the quick resolve and special thanks for this kata :-)

  • Default User Avatar

    The test cases in the javascript translation can be above 1000 so recursion is to slow.

  • Custom User Avatar

    You're right it works fine.

  • Custom User Avatar

    I'm using javascript.

  • Default User Avatar

    @bkaes

    Thanks, I've added your assertFuzzyEquals function to the test case and I am using it for the random tests.

    @GiacomoSorbi

    I hope this sorts things out.

    Thanks to both of you for your help : )

  • Custom User Avatar

    The "Submission timed out" is a Codewars internal thingy (check the GitHub wiki on more information about that). However, a simple recursive will fail, since each non-terminating call will run the function twice, resulting in an exponential runtime (O(2^n)). Just draw the callgraph on a piece of paper and you will notice that it get's quite big for small values like 5.

  • Custom User Avatar

    Or that due to a lack of precision in calculating the answers it's expecting a number that is not actualy a Lucas number ?

    Yup. The random numbers (or the result of lucasnum) in JavaScript is too large for an integer with 32 bits, therefore, JavaScript automatically switches to double. You need to handle comparisons on floating point values with care. You can use something like the function below to handle those:

    var assertFuzzyEquals = function(actual, expected, msg){
        var inrange = Math.abs((actual - expected) / expected) <= 1e-12;
        Test.expect(inrange,
          msg || "Expected value near " + expected.toExponential(13) +
                 ", but got " + actual.toExponential(13)
        );
    }
    

    Alternatively you could make sure that none of the numbers exceed the range of an int32, e.g. use smaller numbers in the random examples.

  • Default User Avatar

    What language are you using?

  • Loading more items...