Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Finally it works!
Thank you for your feedback and for your kata.
I think my problem where with big integers!
Ok!
Now I pass the -1 to -50 but I fail on the random.
Thank you I am going to see why!
I've changed the tests a bit try now.
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:
NaMe613, I pass 57 tests before the first fail.
The test that fails says:
Thank you for your feedback.
My apologies for not having replied yet,could you please clarify how many tests you pass before the error occurs.
Please use three backticks to mark code:
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.
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
Thanks for the quick resolve and special thanks for this kata :-)
The test cases in the javascript translation can be above 1000 so recursion is to slow.
You're right it works fine.
I'm using javascript.
@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 : )
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
.Yup. The random numbers (or the result of
lucasnum
) in JavaScript is too large for an integer with 32 bits, therefore, JavaScript automatically switches todouble
. You need to handle comparisons on floating point values with care. You can use something like the function below to handle those: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.What language are you using?
Loading more items...