diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 29e29d25..17bbf814 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -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, diff --git a/lib/ocaml/baseline/permutations_gen.ml b/lib/ocaml/baseline/permutations_gen.ml new file mode 100644 index 00000000..65b83e8a --- /dev/null +++ b/lib/ocaml/baseline/permutations_gen.ml @@ -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 diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 41d81acd..5eaec083 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -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