Skip to content

Instantly share code, notes, and snippets.

@lawliet89
Last active February 15, 2016 08:29
Show Gist options
  • Save lawliet89/f8836618cec706c82dcc to your computer and use it in GitHub Desktop.
Save lawliet89/f8836618cec706c82dcc to your computer and use it in GitHub Desktop.
Tail recursive Fibonacci Sequence
open System
// Tail recursive Fibonacci
// BigInt -> BigInt
let bigFib n =
let rec loop previous previousPrevious = function
| n when n = 0I -> previousPrevious
| n -> loop (previous + previousPrevious) previous (n - 1I)
loop 1I 0I n
let main() =
[0I .. 100I] |> Seq.iter (fun x -> printfn "fib(%O) = %O" x (bigFib x))
Console.ReadKey() |> ignore
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment