Created
March 14, 2018 21:50
-
-
Save venil7/bb810c669636a9b9597c4f776fec9dee to your computer and use it in GitHub Desktop.
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
| 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