Python Forum

Full Version: Linear Fibonacci sequence
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Currently learning Python recursion and stuck on how to write linear-time fib function:

def goodfib(k):
    if k == 0: return 0, 0, 1
    if k == 1: return 1, 0, 1
    u = goodfib(k - 1)
    ### fill in one line of code here to finish the goodfib function
This is the code the teacher gave us that we're to finish with a single line of code. The last number (1) returned in the base cases, btw, is just a measurement of the # of iterations. So you could pretend it wasn't there for all intents and purposes. Any help?
What is u? How do you calculate the next number of the sequence?