-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Recursion", exercise 2 #24
Comments
|
|
|
True |
|
def test_fib(n, expected): def fib(n): print(test_fib(0,0)) True |
def fib_check(n,expected): def fib(n): print fib(5) {5} print fib_check(11,89) {True} |
|
I've found this recursive algorithm very resource-consuming because it has to calculate each previous number for every number, so I've used low inputs to mitigate the effect. I guess there's a faster way to do that...maybe creating a list to store numbers and reduce the counting?
|
|
|
def test_fab(n,expected): def fab(n): |
print(test_fib(1,1)) #true |
|
|
|
#Test case for the algorithm #Code of the algorithm print(test_fib(7, 13)) |
|
Hi guys, here my take on the exercise (source code available online):
Some comments:
|
Define a recursive function
def fib(n)
that implements the algorithm to find the nth Fibonacci number – where ifn
is less than or equal to 0, then 0 is returned as result; ifn
is equal to 1, then 1 is returned; otherwise, return the sum of the same function called withn-1
andn-2
as input. Please accompany the function with the related test case.The text was updated successfully, but these errors were encountered: