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
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:
12
lib/ocaml/baseline/combinations.ml
Normal file
12
lib/ocaml/baseline/combinations.ml
Normal 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])
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
"calc.ml": 13,
|
"calc.ml": 13,
|
||||||
"catalan.ml": 42,
|
"catalan.ml": 42,
|
||||||
"closures.ml": 315,
|
"closures.ml": 315,
|
||||||
|
"combinations.ml": 126,
|
||||||
"convex_hull.ml": 5,
|
"convex_hull.ml": 5,
|
||||||
"coin_change.ml": 6,
|
"coin_change.ml": 6,
|
||||||
"coin_min.ml": 6,
|
"coin_min.ml": 6,
|
||||||
|
|||||||
@@ -407,6 +407,14 @@ _Newest first._
|
|||||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||||
recursive match, List.append, List.fold_left.
|
recursive match, List.append, List.fold_left.
|
||||||
|
- 2026-05-11 Phase 5.1 — combinations.ml baseline (C(9, 4) = 126
|
||||||
|
enumerated). Pascal-style recursive split: with first element h,
|
||||||
|
combinations either include h (recurse with k−1 on rest) or
|
||||||
|
exclude h (recurse with k on rest); identity choose k [] = [].
|
||||||
|
C(9, 4) = 126 = 9!/(4!·5!). Tests pure-functional combination
|
||||||
|
enumeration with `List.map` + closure over `h`, `@` append,
|
||||||
|
and `[] | h :: rest` pattern match on shrinking input.
|
||||||
|
200 baseline programs total.
|
||||||
- 2026-05-11 Phase 5.1 — unique_paths_obs.ml baseline (count
|
- 2026-05-11 Phase 5.1 — unique_paths_obs.ml baseline (count
|
||||||
monotone paths in 4×4 grid with obstacles at (1,1),(2,3),(3,0)
|
monotone paths in 4×4 grid with obstacles at (1,1),(2,3),(3,0)
|
||||||
= 3). Standard 2D DP with obstacle gating: dp[i][j] = dp[i-1][j]
|
= 3). Standard 2D DP with obstacle gating: dp[i][j] = dp[i-1][j]
|
||||||
|
|||||||
Reference in New Issue
Block a user