Last active
March 12, 2016 13:46
-
-
Save DavidBrower/9af42eb2a7720cc9ac0c to your computer and use it in GitHub Desktop.
Even Fibonacci Numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million. | |
let fibonacciSequence = Seq.unfold(fun (a, b) -> Some(a + b, (b, a + b))) (0L, 1L) | |
fibonacciSequence | |
|> Seq.takeWhile (fun x -> x < 4000000L) | |
|> Seq.filter (fun x -> x % 2L = 0L) | |
|> Seq.sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment