Created
August 22, 2024 01:22
-
-
Save glinesbdev/f56527a5a5e34511d7b50d3e5f492842 to your computer and use it in GitHub Desktop.
Code Wars Ocaml Powers of Two kata
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
let rec power x n = | |
match n with | |
| 0 -> 1 | |
| _ -> x * (power x (n - 1)) | |
let powersOfTwo n = | |
let rec loop acc d = | |
match d with | |
| 0 -> acc | |
| x -> loop (acc @ [power 2 x]) (x - 1) | |
in | |
List.sort compare (loop [1] n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment