Project Euler #2 in F# Project Euler Problem 2 asks for the sum of all even Fibonacci numbers below 4 million.

My first attempt at this problem using functional programming with F#. I would've liked to use some kind of take-while function to keep generating Fibonacci numbers until they fulfilled certain conditions, but alas I could not find such a thing in F#.

open System

let rec fib n = match n with
                | 0 | 1 | 2 -&gt; n
                | _ -&gt; fib (n - 1) + fib (n - 2)

let rec nOfFibTermsUpUntil x y = if fib (y + 1) &lt; x then nOfFibTermsUpUntil x (y + 1) else y

[for n in 0..nOfFibTermsUpUntil 4000000 0 -&gt; fib n]
|&gt; List.filter (fun x -&gt; x % 2 = 0)
|&gt; List.sum
|&gt; printf "The sum of Fibonacci terms up until 4,000,000 is: %d"
Console.ReadKey () |&gt; ignore
I discovered an (arguably) better way of doing this in F# using Seq.unfold and tuples. I'll post the solution below. 

open System

(1,1) |&gt; Seq.unfold (fun (a, b) -&gt; Some(a + b, (b, a + b)))
|&gt; Seq.takeWhile (fun x -&gt; x &lt;= 4000000)
|&gt; Seq.sumBy (fun x -&gt; if x % 2 = 0 then x else 0)
|&gt; printf "The sum of Fibonacci terms up until 4,000,000 is: %d"
Console.ReadKey () |&gt; ignore