diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 01db65d7..90b61eb0 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -75,6 +75,7 @@ "max_product3.ml": 300, "max_run.ml": 5, "mod_inverse.ml": 27, + "josephus.ml": 11, "json_pretty.ml": 24, "kadane.ml": 6, "lambda_calc.ml": 7, diff --git a/lib/ocaml/baseline/josephus.ml b/lib/ocaml/baseline/josephus.ml new file mode 100644 index 00000000..0d1970c0 --- /dev/null +++ b/lib/ocaml/baseline/josephus.ml @@ -0,0 +1,7 @@ +let rec josephus n k = + if n = 1 then 0 + else (josephus (n - 1) k + k) mod n + +;; + +josephus 50 3 + 1 diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index b4f6ac7e..bb56d80e 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,11 @@ _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 — josephus.ml baseline (Josephus problem, + n=50 k=3 → survivor at position 11, 1-indexed). Uses the classic + recursive formula: J(1, k) = 0; J(n, k) = (J(n-1, k) + k) mod n. + Returns 0-indexed survivor; we add 1 for human readability. Tests + recursion, mod, integer arithmetic. 136 baseline programs total. - 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,