Page 3 of 3

Re: Problem 2: Even Fibonacci numbers

Posted: Tue Jul 16, 2013 5:06 pm
by mdean
The problem states "by starting with 1 and 2, the first 10 terms will be..."

Re: Problem 002

Posted: Thu Nov 28, 2013 6:09 am
by pcworx
This maybe a dumb question but on problem 2 what do you start with for the 1st number in your loop?

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.


The problem clearly states to start with 1 and 2, but when it says the first 10 terms will be 1,2,3,5..........
the only way to get the terms 1 and 2 are to start with 0 correct? start with 0 would result in this set of fibo's: 0,1,2,3,5,8........ 0+1=1, 1+1=2, 1+2=3, 2+3=5, 3+5=8........ and so on. Or are 1 and 2 just assumed to be the first fibo's and therefore 2 would be the first number that would be added to get the sum of the positive fibo's? Maybe I am reading to much into it?

Thanks,
Dan

Re: Problem 002

Posted: Thu Nov 28, 2013 8:00 am
by nicolas.patrois
It’s problem #2, you should not search too far away.

Re: Problem 002

Posted: Fri Nov 29, 2013 2:35 am
by dawghaus4
pcwork,

I don't like the statement in the problem that "the" Fibonacci sequence starting with 1 and 2 …, since "the" Fibonacci sequence starts with 1 and 1. Regardless, the answer would not change.

Note, the Fibonacc sequence is usually defined recursively. As all recursive definitions, starting value(s) have to be given. Since the definition is that each term is given by adding the two previous terms, two starting values have to be given. Here, they were given to be 1 and 2. But, again, it does not matter whether or not you start with 1 and 1 or with 1 and 2, the sum of the even Fibonacci numbers that do not exceed 4 million will be the same.

As a tease, it is possible to get the answer without adding them!

Re: Problem 002

Posted: Fri Nov 29, 2013 3:43 pm
by pcworx
Thanks guys,

Seems my algorithm in my head for the math was correct it was just my algorithm for the python code wasn't quite correct. Fixed that up and solved the problem with no cheating! Well I asked my father but he's a chemist and 84 so that doesn't really count and he tried to get me to do sub-scripted variables using quick basic......but anyways thanks for taking time to look at my question.

Dan

Re: Problem 002

Posted: Wed Feb 12, 2014 10:09 pm
by infinitecampus
can someone look at my code and explain to me why i seem to get a negative number? i'm using bluej (java). thanks

Re: Problem 002

Posted: Wed Feb 12, 2014 10:14 pm
by mpiotte
When computing positive numbers, negative results are often the sign of an overflow problem. When an integer variable increases above its maximum range, the result will appear as a negative number. In this problem, we are only interested in relatively small numbers, so there should be no overflow, unless there is a bug.

Re: Problem 002

Posted: Wed Feb 12, 2014 10:28 pm
by infinitecampus
Thank you very much! Solved it in a pinch thanks to that!

Re: Problem 002

Posted: Sat Nov 01, 2014 4:15 pm
by adhirramjiawan
rjgonza wrote:I am having a little trouble with this one. I think I may be interpreting the question incorrectly. The value in question is the actual terms of the sequence, not the corresponding position in the sequence correct? If that is the case then I am not sure why my code is not working. Would I be able to pm it to someone to give it a quick glance?
I've also struggled with this a bit. The value of the Fibonacci number must not exceed 4 million.

Re: Problem 002

Posted: Thu Nov 13, 2014 12:15 am
by Ike
I was also initially confused by the wording of this problem. I first thought that the answer would be the sum of four million numbers of the sequence rather than the sum of all of the numbers in the sequence under four million. I got it now though!

Re: Problem 002

Posted: Fri Mar 04, 2016 8:07 pm
by venomnert
I am sorry if I my response violates any kind of rule. Please excuse me since this is my first time posting.

I was wondering if it is possible to solve the problem using iteration?

Re: Problem 002

Posted: Fri Mar 04, 2016 11:25 pm
by v6ph1
venomnert wrote:I was wondering if it is possible to solve the problem using iteration?
Why not? - Iterate through the list of Fibonacci numbers.
You can solve this problem using a lot of different algorithms.

Re: Problem 002

Posted: Wed Jun 22, 2016 8:53 pm
by kraapi
Hello,

I'm quite a beginner in programming, I can programme simple stuff but no complex algorithms. So the problem I come across is that, I managed to count the Fibonacci sequence from 1 to 10. It was quite a pain in my a** to figure it out. And I can count the sequence even further. I managed it with swapping variables. My problem is that I don't really understand what I have to do for this problem. I assume, that I need to find even numbers that are under 4 million in the Fibonacci sequence. And then sum them together. So in my theory the sequence has to stop at somewhere 4 million. To find the even numbers is simple, I just have to look up which numbers divide by 2 and add them together for the sum. But I can't figure it out which numbers should be used for the sum.

Best Regards

EDIT: I found the solution for this problem. It was much easier than I thought. I read this thread severals times through :D And I found the answer to my problem, here :D Some times is the answer beneath your nose, used my grandma to say :D

-kraapi

Re: Problem 002

Posted: Wed Oct 24, 2018 5:08 pm
by mafridi
Hi,

I solved this problem using python but I'm also trying to learn the formula. If the example provides us with 1 2 3 5 8 13 21 34 55 89 144, can someone please PM me how the formula which is provided in the answer would be filled out? Instead of using 4 million as the threshold for a value lets just use 200 as an example.

I read the WikiPedia on Fibonacci numbers but don't understand how the formula is being used. I just want to see what the filled out formula looks like so I can better understand it.

Thank you.

Re: Problem 002

Posted: Wed Oct 24, 2018 9:46 pm
by kenbrooker
mafridi...

Please see PM from me...