Skip to content
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

Open
essepuntato opened this issue Oct 14, 2020 · 18 comments
Open

Lecture "Introduction to Computational Thinking", exercise 2 #2

essepuntato opened this issue Oct 14, 2020 · 18 comments
Labels

Comments

@essepuntato
Copy link
Contributor

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?

@IlaRoss
Copy link

IlaRoss commented Oct 14, 2020

Is it 13?
Wow, I had never seen that function to calculate a Fibonacci number! It is simply great :-D

@SarahTew
Copy link

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.

@SusannaPinotti
Copy link

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

@diegochillo
Copy link

Exploding the whole recursion:

f(0)=0
f(1)=1
f(2)=f(1)+f(0)=1
f(3)=f(2)+f(1)=2
f(4)=f(3)+f(2)=3
f(5)=f(4)+f(3)=5
f(6)=f(5)+f(4)=8
f(7)=f(6)+f(5)=13

@denizovski
Copy link

denizovski commented Oct 14, 2020

In Fibonacci function, the terms are numbered from 0 onwards like this:
n=0,1,2,3,4,5,6,7...
fib=0,1,1,2,3,5,8,13...
In this way, 7 as an input equals 13.

@lauratravaglini
Copy link

The Fibonacci sequence is 0,1,1,2,3,5,8,13,21,...
If n is 7, returns the sum of the same function with n-1 as input and the same function with n-2 as input.
Fib(7)=Fib(7-1)+Fib(7-2) -> Fib(7)=Fib(6)+Fib(5) -> Fib(7)=8+5 -> Fib(7)= 13
(usually when I think I’ve figured something out in math I’m actually wrong, so I don’t know, I tried)

@AlessandraFa
Copy link

AlessandraFa commented Oct 15, 2020

Using 7 as input, the result of applying the recursive definition of the Fibonacci function is 13.
The Fibonacci sequence is the series of numbers fib=0, 1, 1, 2, 3, 5, 8, 13, 21,...x(n-1+n-2).
Each number in the sequence xn is the result of the sum of the previous ones xn-1 and xn-2. The recursive definition returns 0 if the input is less or equal to 0, so 1 should be considered as 1st term.
Since 7 is the input number, the result will be the 7th number x7 of the series, namely the sum of x6 and x5. So, xn=xn-1+xn-2 corresponds, in this case, to x7 = x6+x5=5+8=13.

@gabrielefiorenza
Copy link

The answer is 13, because in the Fibonacci sequence each number is the sum of the two preceding ones, starting from 0 and 1.

@samuelespotti
Copy link

The Fibonacci sequence is 0,1,1,2,3,5,8,13,21,...
If n is 7, we have to do the sum of " n-1" as input (7-1=6) and t n-2 as input (7-2=5)
Fib(7)=Fib(6)+Fib(5) -> Fib(7)=8+5 -> Fib(7)= 13

@giorgiasampo
Copy link

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.
7 is different from 1 so we don't return 1.
The Fibonacci sequence goes like 0,1,1,2,3,5,8,13,22.... and so on, where all the numbers correspond to the sum of the previous two.
Going on with the instructions given,we get the sum of the function for n-1 (6) plus the function for n-2 (5) which is 8+5=13.

@alicebordignon
Copy link

alicebordignon commented Oct 15, 2020

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)

@falcon1982
Copy link

falcon1982 commented Oct 15, 2020

F(7)=
F(6)+F(5)=
(F(5)+F(4) ) + (F(4)+F(3) )=
(F(4)+F(3)+F(3)+F(2)) + ( F(3)+F(2)+ F(2)+1 )=
(F(3)+F(2)+F(2)+1 +F(2)+1 + 1+0) +(F(2)+1 +1+0+1+0+1)=
(F(2)+1 +1+0 +1+0 +1+1+0 +1+1+0)+(1+0 +1+1+0+1+0+1)=
(1+0 +1 +1+0 +1+0 +1+1+0 +1+1+0)+(1+0 +1+1+0+1**+0+1**)=
8+5=13

@diegochillo
Copy link

F(7)=
F(6)+F(5)=
(F(5)+F(4) ) + (F(4)+F(3) )=
(F(4)+F(3)+F(3)+F(2)) + ( F(3)+F(2)+ F(2)+1 )=
(F(3)+F(2)+F(2)+1 +F(2)+1 + 1+0) +(F(2)+1 +1+0+1+0+1)=
(F(2)+1 +1+0 +1+0 +1+1+0 +1+1+0)+(1+0 +1+1+0+1+0+1)=
(1+0 +1 +1+0 +1+0 +1+1+0 +1+1+0)+(1+0 +1+1+0+1)=
8+5=13

There's a "+0+1" missing in the penultimate row

@falcon1982
Copy link

And I double checked it 🤦‍♂️

@DeniseBas
Copy link

F(7)=F(5)+F(6) -> F(7)=8+5 so it means that F(7)=13

@Camillaneri
Copy link

n=7

I have to sum the result of the functions of n-1 and n-2

7-1=6
7-2=5

I have already calculated the functions of 6 and 5 with the same procedure, wich are 8 and 5

8+5=13
the function of 7 Is 13

@essepuntato
Copy link
Contributor Author

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.

@Maedeam
Copy link

Maedeam commented Oct 16, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests