Problem 002
Forum rules
As your posts will be visible to the general public you
are requested to be thoughtful in not posting anything
that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
As your posts will be visible to the general public you
are requested to be thoughtful in not posting anything
that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
In particular don't post any code fragments or results.
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
Re: Problem 2: Even Fibonacci numbers
The problem states "by starting with 1 and 2, the first 10 terms will be..."
Re: Problem 002
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 evenvalued 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
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 evenvalued 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
 nicolas.patrois
 Posts: 117
 Joined: Fri Jul 26, 2013 3:54 pm
 Contact:
Re: Problem 002
It’s problem #2, you should not search too far away.
Re: Problem 002
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!
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
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 subscripted variables using quick basic......but anyways thanks for taking time to look at my question.
Dan
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 subscripted variables using quick basic......but anyways thanks for taking time to look at my question.
Dan

 Posts: 2
 Joined: Wed Feb 12, 2014 10:07 pm
Re: Problem 002
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
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.

 Posts: 2
 Joined: Wed Feb 12, 2014 10:07 pm
Re: Problem 002
Thank you very much! Solved it in a pinch thanks to that!

 Posts: 1
 Joined: Sat Nov 01, 2014 4:11 pm
Re: Problem 002
I've also struggled with this a bit. The value of the Fibonacci number must not exceed 4 million.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?
Re: Problem 002
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!
"I have no special talents, I am just passionately curious."  A.E.
Re: Problem 002
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?
I was wondering if it is possible to solve the problem using iteration?
Re: Problem 002
Why not?  Iterate through the list of Fibonacci numbers.venomnert wrote:I was wondering if it is possible to solve the problem using iteration?
You can solve this problem using a lot of different algorithms.
Re: Problem 002
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 And I found the answer to my problem, here Some times is the answer beneath your nose, used my grandma to say
kraapi
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 And I found the answer to my problem, here Some times is the answer beneath your nose, used my grandma to say
kraapi
Re: Problem 002
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.
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.
 kenbrooker
 Posts: 124
 Joined: Mon Feb 19, 2018 3:05 am
 Location: Oregon, USA
Re: Problem 002
mafridi...
Please see PM from me...
Please see PM from me...
"Good Judgment comes from Experience;
Experience comes from Bad Judgment..."
Experience comes from Bad Judgment..."