Last active
July 7, 2024 12:51
-
-
Save espio999/7a8d089b05226fec5c4c4fffcd084e0e to your computer and use it in GitHub Desktop.
F# fibonacci module
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
module fibonacci | |
let rec fib n = | |
match n with | |
| 0 | 1 -> n | |
| n -> fib (n-1) + fib (n-2) | |
let fib_tail_recursion n = | |
let rec loop acc1 acc2 n = | |
match n with | |
| 0 -> acc1 | |
| 1 -> acc2 | |
| _ -> loop acc2 (acc1 + acc2) (n - 1) | |
loop 0 1 n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment