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.
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?
Why would
L(n) = L(n + 2) - L(n + 1)
not work ?example:
another one:
and so on ....
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.
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.
I would suggest using L(-n) = L(n)(-1)^n
I've modified the description,
can please check and if it's ok resolve the issue.
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.
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...