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.
sorry,not know the rules very much. some trains have discuss button in it, but not this
the code is very simple:
def fib(n):
"""Calculates the nth Fibonacci number"""
print(n)
a,b = 0,1
while n>1:
if n%2 == 0:
n-=2
a,b = a+b, a+2b
else:
n-=1
a,b = b, a+b
#print(n,a,b)
while n<0:
if n%2 == 0:
n+=2
a,b = 2a-b, b-a
else:
n+=1
a,b = b-a,a
#print(n,a,b)
if n==0:
return a
elif n==1:
return b
print(fib(1000000))
for fib(1000000)
real 0m43.723s
user 0m41.752s
sys 0m0.206s
fib(84362)
for kata "The Millionth Fibonacci Kata", my code run no more than 0.4 seconds in my computer, why get a timeout @codewars?
real 0m0.337s
user 0m0.331s
sys 0m0.005s
if i don't add print in the program, just get a timeout with nothing
if i add any print in the program, it just complains about too many print in my program
This comment is hidden because it contains spoiler information about the solution