-
Notifications
You must be signed in to change notification settings - Fork 9
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 "Introduction to Computational Thinking", exercise 2 #2
Comments
Is it 13? |
Reading the natural language definition it only returns 0 for the 0th term, not the first. So I think this definition of the Fibonacci sequence eliminates '0' as the first term and instead starts with '1' as the first term. If that's the case then the input '7' yields 13. |
Following the recursive method for the Fibonacci function described in the second natural language definition, the value resulting from the input "7" is the sum of the Fibonacci function for "7-1" and "7-2". So Fib(7)=Fib(6)+Fib(5)=8+5=13 |
Exploding the whole recursion: f(0)=0 |
In Fibonacci function, the terms are numbered from 0 onwards like this: |
The Fibonacci sequence is 0,1,1,2,3,5,8,13,21,... |
Using 7 as input, the result of applying the recursive definition of the Fibonacci function is 13. |
The answer is 13, because in the Fibonacci sequence each number is the sum of the two preceding ones, starting from 0 and 1. |
The Fibonacci sequence is 0,1,1,2,3,5,8,13,21,... |
Applying the second definition we get 7 as an input: being 7 different from 0 and not below it we don't return 0 as a result and proceed with the instructions. |
According to the Fibonacci sequence (0, 1, 1, 2, 3, 5, 8, 13, 21...) the result will be the sum of the 2 previous numbers. So, if the input number is 7, we might sum (7-1=fib6) and (7-2=fib5) equals to 8+5 and obtain 13 as the fib(7) |
F(7)= |
There's a "+0+1" missing in the penultimate row |
And I double checked it 🤦♂️ |
F(7)=F(5)+F(6) -> F(7)=8+5 so it means that F(7)=13 |
n=7 I have to sum the result of the functions of n-1 and n-2 7-1=6 I have already calculated the functions of 6 and 5 with the same procedure, wich are 8 and 5 8+5=13 |
Hi all, Thanks for your answer. Someone said that "0" is not the first element while "1" is. Could you explain what you mean? Anyway, the solution has been provided in the section linking the chapter in the main page of the course. |
The function for calculating the 7th Fibonacci number takes as input an integer “7”. If “7” is less than or equal to 0, then 0 is returned as a result. Otherwise, if “7” is equal to 1, then 1 is returned. Otherwise, return the sum of the same function with “7-1” as input and still the same function with “7-2” as input. |
What is the result of applying the second natural language definition of the Fibonacci function in Section "Natural languages vs programming languages" using “7” as input?
The text was updated successfully, but these errors were encountered: