Skip to content

Instantly share code, notes, and snippets.

@DavidBrower
Last active March 12, 2016 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidBrower/9af42eb2a7720cc9ac0c to your computer and use it in GitHub Desktop.
Save DavidBrower/9af42eb2a7720cc9ac0c to your computer and use it in GitHub Desktop.
Even Fibonacci Numbers
//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