Now that my previous WPF project is done, I can get back to some F#! Again, I am using Project Euler as my demo platform.
Project Euler: Problem 2
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, ...
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
Given the first 10 terms, the sum of the even valued terms will be:
2 + 8 + 34 = 44
This problem is divided into two parts: creating the Fibonacci sequence and then summing up the even valued terms. The listing illustrates the solution.
This was not the best approach to use, in that I sort of cheated to know how many terms I need to iterate to fall in the 4 million range. That is, I got these numbers by trial and error since fibo 32 = 3524578 and fibo 33 = 5702887, I knew that by using 33, I will be in the range needed. However, I will try to address this in a revised version. Since it's been a while since I did F#, I wanted to just knock this one out as quickly as possible. My apologies for the little trick.