ocaml: phase 5.1 permutations_gen.ml baseline (24 perms, 12 with a<b ends)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Recursive permutation generator via fold-pick-recurse:
let rec permutations xs = match xs with
| [] -> [[]]
| _ ->
List.fold_left (fun acc x ->
let rest = List.filter (fun y -> y <> x) xs in
let subs = permutations rest in
acc @ List.map (fun p -> x :: p) subs
) [] xs
For permutations of [1; 2; 3; 4] (24 total), count those whose
first element is less than the last:
match p with
| [a; _; _; b] when a < b -> count := !count + 1
| _ -> ()
By symmetry, exactly half satisfy a < b = 12.
Tests List.filter, recursive fold with append, fixed-length
list pattern [a; _; _; b] with multiple wildcards + when guard.
183 baseline programs total.
This commit is contained in:
@@ -134,6 +134,7 @@
|
||||
"pascal.ml": 252,
|
||||
"peano.ml": 30,
|
||||
"perfect.ml": 3,
|
||||
"permutations_gen.ml": 12,
|
||||
"pi_leibniz.ml": 314,
|
||||
"prefix_sum.ml": 66,
|
||||
"pretty_table.ml": 64,
|
||||
|
||||
20
lib/ocaml/baseline/permutations_gen.ml
Normal file
20
lib/ocaml/baseline/permutations_gen.ml
Normal file
@@ -0,0 +1,20 @@
|
||||
let rec permutations xs =
|
||||
match xs with
|
||||
| [] -> [[]]
|
||||
| _ ->
|
||||
List.fold_left (fun acc x ->
|
||||
let rest = List.filter (fun y -> y <> x) xs in
|
||||
let subs = permutations rest in
|
||||
acc @ List.map (fun p -> x :: p) subs
|
||||
) [] xs
|
||||
|
||||
;;
|
||||
|
||||
let ps = permutations [1; 2; 3; 4] in
|
||||
let count = ref 0 in
|
||||
List.iter (fun p ->
|
||||
match p with
|
||||
| [a; _; _; b] when a < b -> count := !count + 1
|
||||
| _ -> ()
|
||||
) ps;
|
||||
!count
|
||||
@@ -407,6 +407,16 @@ _Newest first._
|
||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||
recursive match, List.append, List.fold_left.
|
||||
- 2026-05-11 Phase 5.1 — permutations_gen.ml baseline (enumerate all
|
||||
24 permutations of [1;2;3;4], count those with first<last = 12).
|
||||
Recursive build via fold-pick-recurse:
|
||||
permutations xs = ∪ over x ∈ xs of x :: p for p ∈ permutations
|
||||
(xs \ {x})
|
||||
The pattern `[a; _; _; b] when a < b` then filters fixed-length
|
||||
4-element permutations on the head/tail relation. Exactly half
|
||||
(12) satisfy a < b by symmetry. Tests `List.filter`, recursive
|
||||
fold with append, `[a; _; _; b]` fixed-length list pattern with
|
||||
multiple wildcards and a `when` guard. 183 baseline programs total.
|
||||
- 2026-05-11 Phase 5.1 — regex_simple.ml baseline (recursive `.`/`*`
|
||||
regex matcher; over 4×7 = 28 (pattern, text) combos, 7 match).
|
||||
Cases per pattern:
|
||||
|
||||
Reference in New Issue
Block a user