Much like the previous Euler project solution, I was going for a low coupling high cohesion object oriented approach. Did I achieve that? Well, I'll leave that up to the reader to decide. However, it is another stand alone program that will sum up all the even terms of the Fibonacci sequence when the terms are below 4 million. I took the non-recursive approach because I was always bothered by the fact the the recursive approach can fill up the stack and run out of memory. I kn ow in school this is the most common approach when professors begin to teach recursion. It always bothered me though because your severely wasting the stack. However, recursion is a neat little trick that can really boggle the mind sometimes. I understand the fascination. Below is the problem statement and code for the readers' exploration.
"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." -projecteuler.net/problem=2-
0 Comments
Leave a Reply. |