Python Forum
Linear Fibonacci sequence
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linear Fibonacci sequence
#1
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?
Reply
#2
What is u? How do you calculate the next number of the sequence?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Assistance with Fibonacci code Colombian1976 3 2,884 Feb-17-2024, 12:09 PM
Last Post: Pedroski55
  Fibonacci sequence problem is confusing me adam10e10 2 3,487 Apr-04-2019, 10:55 AM
Last Post: perfringo
  Help needed on Fibonacci series nvakada 1 2,454 Apr-25-2018, 07:12 PM
Last Post: micseydel
  Help with fibonacci sequence masonmoore93 2 7,967 Oct-01-2017, 12:56 AM
Last Post: masonmoore93
  Fibonacci sequence logic 3 4,717 Jun-11-2017, 08:23 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020