Last active
February 15, 2016 08:29
-
-
Save lawliet89/f8836618cec706c82dcc to your computer and use it in GitHub Desktop.
Tail recursive Fibonacci Sequence
This file contains hidden or 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
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