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.
I encountered the same problem (with the some answer in Ruby), and hadn't a clue how to fix (circumvent) the problem in the test cases - because it is clear that the problem is there. While debugging, I put a
p string
as the first line in the method... and got the solution accepted. You might want to try that.Do you have the problem with other Ruby versions as well?
I encountered the same problem (with the very obvious expression in Ruby as my answer), and hadn't a clue how to fix (circumvent) the problem in the test cases. While debugging, I put a
p string
as the first line in the method... and got the solution accepted. You might want to try that.Perhaps (now that I think of it) it has something to do with the Ruby version we're using?
I encountered the same problem (with the very obvious answer in Ruby), and hadn't a clue how to fix (circumvent) the problem in the test cases. While debugging, I put a
p string
as the first line in the method... and got the solution accepted. You might want to try that.See https://en.wikipedia.org/wiki/Fibonacci_number#Negafibonacci for an explanation of Fibonacci numbers for negative numbers.
And make sure that you compute the power correctly: put parenthesis around the
-1
, like in(-1) ** ((n.abs)+1) * fib(n.abs) if n < 0
See https://en.wikipedia.org/wiki/Fibonacci_number#Negafibonacci for a description of negative Fibonacci numbers.
BTW, I struggled with this as well, but discovered that (in Ruby) you should put parenthesis around the -1 to have the -1**n work correctly, thus
return (-1) ** ((n.abs)+1) * fib(n.abs) if n < 0
This comment is hidden because it contains spoiler information about the solution