ocaml: phase 5.1 combinations.ml baseline (C(9, 4) = 126)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

Pascal-recursion combination enumerator:

  let rec choose k xs =
    if k = 0 then [[]]
    else match xs with
      | [] -> []
      | h :: rest ->
        List.map (fun c -> h :: c) (choose (k - 1) rest)
        @ choose k rest

  C(9, 4) = |choose 4 [1; ...; 9]| = 126

Tests pure-functional enumeration with List.map + closure over h,
@ append, [] | h :: rest pattern match on shrinking input.

200 baseline programs total -- milestone.
This commit is contained in:
2026-05-11 05:25:03 +00:00
parent 3ccce58e0a
commit fad81e0b0c
3 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
let rec choose k xs =
if k = 0 then [[]]
else
match xs with
| [] -> []
| h :: rest ->
List.map (fun c -> h :: c) (choose (k - 1) rest)
@ choose k rest
;;
List.length (choose 4 [1; 2; 3; 4; 5; 6; 7; 8; 9])

View File

@@ -29,6 +29,7 @@
"calc.ml": 13,
"catalan.ml": 42,
"closures.ml": 315,
"combinations.ml": 126,
"convex_hull.ml": 5,
"coin_change.ml": 6,
"coin_min.ml": 6,