diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index e338cc68..01db65d7 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -95,6 +95,7 @@ "palindrome_sum.ml": 49500, "paren_depth.ml": 7, "partition.ml": 3025, + "partition_count.ml": 176, "pancake_sort.ml": 910, "pascal.ml": 252, "peano.ml": 30, diff --git a/lib/ocaml/baseline/partition_count.ml b/lib/ocaml/baseline/partition_count.ml new file mode 100644 index 00000000..f91bfca8 --- /dev/null +++ b/lib/ocaml/baseline/partition_count.ml @@ -0,0 +1,13 @@ +let partition_count n = + let dp = Array.make (n + 1) 0 in + dp.(0) <- 1; + for k = 1 to n do + for i = k to n do + dp.(i) <- dp.(i) + dp.(i - k) + done + done; + dp.(n) + +;; + +partition_count 15 diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index ef2b5f7b..b4f6ac7e 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,12 @@ _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-10 Phase 5.1 — partition_count.ml baseline (number of + integer partitions of 15 = 176). Classic DP: dp[0] = 1; for each + k from 1..n, for each i from k..n, dp[i] += dp[i - k]. O(n²) time, + O(n) space. p(15) = 176 partitions of 15. Tests Array.make, array + set/get with `.(i)<-` / `.(i)`, nested for-loops, ref deref. + 135 baseline programs total. - 2026-05-10 Phase 5.1 — pythagorean.ml baseline (count primitive Pythagorean triples with hypotenuse ≤ 100 = 16). Uses Euclid's formula: for coprime m > k of opposite parity, the triple