Ad
  • 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?

  • Default User Avatar

    Why would L(n) = L(n + 2) - L(n + 1) not work ?

    example:

    L(-1) = L(1) - L(0) = 
    
    L(-1) = 1 - 2 = 
    
    L(-1) = -1
    

    another one:

    L(-2) = L(0) - L(-1) = 
    
    L(-2) = 2  -  -1  = 
    
    L(-2) = 3
    

    and so on ....

  • Custom User Avatar

    My code passes tons of tests, including all those left below but when I submit my code I get the error:
    "Process was terminated. It took longer than 6000ms to complete"
    Can I not use recursion to solve this problem? Is it too computationally complex?

    I am also getting a lot of "submission timed out" errors.

  • Default User Avatar

    I'm sorry but I still don't quite grasp what the problem is, can you please clarify.

    Is it that the random tests expect a level of precision that is not 6kyu to provide?

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

    Or something else entirely and I'm totaly off target.

  • Custom User Avatar

    I would suggest using L(-n) = L(n)(-1)^n

  • Default User Avatar

    I've modified the description,
    can please check and if it's ok resolve the issue.

  • Custom User Avatar

    The extension to negative integers is not fully explained in the instructions. Unless the "research" on external resources are part of the kata, these rules should be clearly explained.

  • Custom User Avatar

    It seems to me that your code has both problems in computing the right numbers and giving it the right sign (+/-); for the latter, see my reply below to Neoslide comment.

  • Loading more items...