Skip to content

Instantly share code, notes, and snippets.

@intv0id
Last active November 7, 2019 17:03
Show Gist options
  • Save intv0id/089b15e48824b4ff1f30e9b02725966e to your computer and use it in GitHub Desktop.
Save intv0id/089b15e48824b4ff1f30e9b02725966e to your computer and use it in GitHub Desktop.
let rec combinations k m = match k, m with
| k, m when k < 0 || m < 0 -> failwith "ki or mi negative"
| k, m when k > m -> failwith "k > m"
| 0, 0 -> [[]]
| 0, m -> map (concat false) (combinations 0 (m-1))
| k, m when k = m -> map (concat true) (combinations (k-1) (m-1))
| k, m -> map (concat true) (combinations (k-1) (m-1)) @ map (concat false) (combinations k (m-1))
;;
let generate m n =
let c = combinations ((m-1) * (n-1)) (m*(n-1)+n*(m-1))
in
let c_array = map Array.of_list c
in
filter (sanity_check m n) c_array
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment