Skip to content

Instantly share code, notes, and snippets.

@b4284
Created May 3, 2016 08:13
Show Gist options
  • Select an option

  • Save b4284/38e5eda863339ab75a487ac1e028ed2a to your computer and use it in GitHub Desktop.

Select an option

Save b4284/38e5eda863339ab75a487ac1e028ed2a to your computer and use it in GitHub Desktop.
(* #require "num";; *)
let fib n =
let rec helper n2 a b =
if n2 = 1 then b else helper (n2 - 1) b (a + b)
in helper n 0 1;;
let fib_big n =
let rec helper n2 a b =
if n2 = 1 then b else helper (n2 - 1) b (Big_int.add_big_int a b)
in helper n (Big_int.big_int_of_int 0) (Big_int.big_int_of_int 1);;
let () = ignore @@ fib_big 1000000;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment