comp-think / 2024-2025

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. 2024/2025).
12 stars 0 forks source link

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

Open essepuntato opened 1 month ago

essepuntato commented 1 month 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?

KikaYang commented 1 month ago

13

nicoldamelio commented 1 month ago

13

digitalctrlv commented 1 month ago

13

or did you mean:

"The function for calculating the nth Fibonacci number takes as input an integer “7”. If “n” is less than or equal to 0, then 0 is returned as a result. Otherwise, if “n” is equal to 1, then 1 is returned. Otherwise, return the sum of the same function with “7-5” as input and still the same function with “7-6” as input." ?

VirgiBo commented 1 month ago

13

maridematteis commented 1 month ago

13

ERendall commented 1 month ago

Err. It should be 13... But I second @digitalctrlv -- I am confused by the command to 'return the sum of the same function n-1 as input and still the same function with 'n-2' as input....'!

Am I missing something?

digitalctrlv commented 1 month ago

Err. It should be 13... But I second @digitalctrlv -- I am confused by the command to 'return the sum of the same function n-1 as input and still the same function with 'n-2' as input....'!

Am I missing something?

Ah I was confused, thanks for pointing it out! It should be of course: F7 = F7-1 + F7-2 = F7 = F6 + F5 F7 = 8 + 5 = 13

In natural language: "Otherwise, return the sum of the same function with "7-1" as input and still the same function with "7-2" as input."

ERendall commented 1 month ago

Wait a minute:

F7 = F7-1 + F7-2 F7 = 6+5 F7 = 11.

Where does the '8' (F8) come from?

Sorry, I may be being very slow, but I really want to get this...

digitalctrlv commented 1 month ago

Wait a minute:

F7 = F7-1 + F7-2 F7 = 6+5 F7 = 11.

Where does the '8' (F8) come from?

Sorry, I may be being very slow, but I really want to get this...

No worries! The Fn represents the input number. 8 is the value of F6 as we see in the sequence below:

Screenshot 2024-10-17 at 15 20 32

And if F5 is 5, that means we have 5 + 8 = 13. Does that make sense?

martinaucch commented 1 month ago

Wait a minute:

F7 = F7-1 + F7-2 F7 = 6+5 F7 = 11.

Where does the '8' (F8) come from?

Sorry, I may be being very slow, but I really want to get this...

I'm writing down as I am trying to understand cause i'm having an hard time as well... @ERendall, Hope it can help. The function for calculating the nth Fibonacci number takes as input an integer “n”. If “n” is less than or equal to 0, then 0 is returned as a result. Otherwise, if “n” is equal to 1, then 1 is returned. Otherwise, return the sum of the same function with “n-1” as input and still the same function with “n-2” as input. That means that if my input number is 7 the result has to be the sum of the same function f(6) and f(5). But those are function not numbers so you are not supposed to sum those as 6 and 5 but as the f of 6 and the f of 5. so f(6)= f(5)+ f(4) f(5) = f(4) + f(3) you need to know to what natural number those function compare to. so given the fact that f(1) = 1 and f(0)=0 (as stated in the natural language definition of the fibonacci sequence) then
f(2)= f(n-1) + f( n-2)= f (1)+ f (0) = 1+0= 1 and so on so f (3)= f(2)+ f(1)= 1+1 = 2 f (4)= f (3)+ f (2) = 2+ 1= 3 f (5) = f (4) + f(3) = 3+ 2 = 5 f (6) = f(5) + f (4) = 5 + 3 =8 f (7) = f(6) + f (5) = 8 + 5 = 13 this i think is the recursive method to calculate the fibonacci number. Now i'm trying to understand the first one, that apparently uses the concept of iteration (?). i'm not sure..

ERendall commented 1 month ago

Ah, I see! Thank you @martinaucch and @digitalctrlv! I got mixed up with the wording of the natural language definition...!

This makes sense, now! I will move on to the first definition, seeing if I have greater luck there!

ValkyrieCain9 commented 1 month ago

13

martinamrc commented 1 month ago

The result I got was 13, although I have to admit that I obtained this result kind of through 'cheating' because following the second natural language definition was a bit confusing in the beginning for its mathematical essence, and mostly because of the sentence "return the sum of the same function", which didn't immediately make me recall the actual mathematical function (like some of the comments stated) and while reading it felt 'unclear'. So I followed the first natural language definition and the C code, and I thought that maybe this exercise was also a way to reflect on how the natural language is more ambiguous for its expressiveness compared to a programming language (though I definitely lacked understanding of the second definition).

OLIVER792001 commented 1 month ago

13

theair-hub commented 1 month ago

The function (F) for calculating the nth Fibonacci number takes as input an integer “7”. If “n” is less than or equal to 0, then 0 is returned as a result. Otherwise, if “n” is equal to 1, then 1 is returned. F0=0 F1=1 Otherwise, return the sum of the same function with “n-1” as input and still the same function (F) with “n-2” as input. F2= F1 (that is n-1= 2-1)+F0 (2-2)= 1 F3= F2+ F1= 1+1= 2 F4= F3+F2= 2+1= 3 F5= F4+F3= 3+2= 5 F6= F5+F4= 5+3= 8 F7= F6+F5= 8+5= 13

Also, I asked a friend of mine who studies Math if that was correct and he said that there is also this other way (I think far more complicated than the other one) but I put it here just for fun :) F7=F6+F5=F5+2(F4)+F3=F4+3(F3)+3(F2)+F1=F3+4(F2)+7(F1)+3(F0)=F2+12(F1)+7(F0)=13(F1)+8(F0)=13+0= 13

rumana-mh commented 1 month ago

Fn= F(n-1)+F(n-2) F7=F(6)+F(5) F7=8+5 =13

Fahmyrose commented 1 month ago

Things to remember:

F(0)= 0 F(1)= 1 F(n)= F(n-1)+F(n-2) --> until i get return of 0 or 1 then sum up

so: F(7) = F(7-1)+F(7-2) = F(6)+F(5) --> I have to find the result of F(6) and F(5) to be able to find out F(7)

that is why: Immagine WhatsApp 2024-10-18 ore 10 34 25_6330df14

The final answer is 13!

I was able to understand how to do the exercise thanks to the help of my colleagues but at first it was really hard for me to understand the command and since I have never used this function calculation I didn't know where to begin to do the sum ups. I didn't even know if I could google the Fibonacci sequence - (0 1 1 2 3 5 8 13 21) that is easier to undestand - because I was trying to see if I could do it without external help since that's how the written exam situation will be etc. I guess that maybe the purpose of the exercise was to understand how programming languages are easier than natural languages since the human computer has to do the calculations by hand and so it is more ambiguous.

simplycyrus99 commented 1 month ago

The Fibonacci sequence builds on each preceding pair, so without knowing the prior two values, you can't compute the next one. SO if you are confused by the whole matter, you have every right to be lmao For example, if you needed to calculate F56, you'd have to know the result of F(55) and F(54). IF you don’t know F(55) and F(54) , then you wouldn't be able to directly calculate F(56) without first figuring out those previous values. However, you can calculate them by starting from the base values, like F(0) and F(1), and working your way up, but it would be a lot of calculations for large numbers like F(56)!

oh and 13 XDD

kettelaugust commented 9 hours ago

13