Skip to content

Instantly share code, notes, and snippets.

@vietnt
Created December 19, 2020 15:27
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 vietnt/6a09f1751072fcf6656b4c56eef7be31 to your computer and use it in GitHub Desktop.
Save vietnt/6a09f1751072fcf6656b4c56eef7be31 to your computer and use it in GitHub Desktop.
let rec fib n =
match n with
| 0 -> 1
| 1 -> 2
| x -> fib (x - 1) + fib (x - 2)
Seq.initInfinite fib
|> Seq.takeWhile (fun n -> n <= 4_000_000)
|> Seq.filter (fun n -> n % 2 = 0)
|> Seq.sum
|> printfn "%A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment