Skip to content

Instantly share code, notes, and snippets.

@venil7
Created March 14, 2018 21:50
Show Gist options
  • Save venil7/bb810c669636a9b9597c4f776fec9dee to your computer and use it in GitHub Desktop.
Save venil7/bb810c669636a9b9597c4f776fec9dee to your computer and use it in GitHub Desktop.
let next = (seq: list(int)) : int =>
switch (seq) {
| [] => 0
| [0] => 1
| [x, y, ..._] => x + y
};
let fib = (n: int) : list(int) => {
let rec fib' = (m: int, seq: list(int)) : list(int) =>
switch (m) {
| x when x == n => [next(seq), ...seq]
| x => fib'(x + 1, [next(seq), ...seq])
};
fib'(0, []);
};
Js.log(fib(26) |> List.rev |> Array.of_list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment