comp-think / 2020-2021

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2020/2021).
14 stars 9 forks source link

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

Open essepuntato opened 3 years ago

essepuntato commented 3 years ago

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 commented 3 years ago

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

SarahTew commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

And I double checked it 🤦‍♂️

DeniseBas commented 3 years ago

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

Camillaneri commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.