Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
Code
Diff
  • open Preloaded;
    
    let fib = (n) => {
      let rec fib_aux = (n, a, b) =>
        if (n <= 0) { a; }
        else { fib_aux(n - 1, b, a +@ b); }
      fib_aux(n, big_int_of_int(0), big_int_of_int(1))
        |> string_of_big_int;
    };
    
    let fib64 = (n) => {
      // Open Int64 locally
      open Int64;
      let rec fib_aux = (n, a, b) =>
        if (n <= 0) { a; }
        else { fib_aux(n - 1, b, add(a, b)); }
      fib_aux(n, zero, one)
        |> to_string;
    };
    
  • 11 open Preloaded;
    22
    33 let fib = (n) => {
    44 let rec fib_aux = (n, a, b) =>
    55 if (n <= 0) { a; }
    66 else { fib_aux(n - 1, b, a +@ b); }
    77 fib_aux(n, big_int_of_int(0), big_int_of_int(1))
    88 |> string_of_big_int;
    99 };
    1010
    11+let fib64 = (n) => {
    12+ // Open Int64 locally
    13+ open Int64;
    14+ let rec fib_aux = (n, a, b) =>
    15+ if (n <= 0) { a; }
    16+ else { fib_aux(n - 1, b, add(a, b)); }
    17+ fib_aux(n, zero, one)
    18+ |> to_string;
    19+};
open Preloaded;

let fib = (n) => {
  let rec fib_aux = (n, a, b) =>
    if (n <= 0) { a; }
    else { fib_aux(n - 1, b, a +@ b); }
  fib_aux(n, big_int_of_int(0), big_int_of_int(1))
    |> string_of_big_int;
};