Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Created August 22, 2024 01:22
Show Gist options
  • Save glinesbdev/f56527a5a5e34511d7b50d3e5f492842 to your computer and use it in GitHub Desktop.
Save glinesbdev/f56527a5a5e34511d7b50d3e5f492842 to your computer and use it in GitHub Desktop.
Code Wars Ocaml Powers of Two kata
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