diff --git a/lib/ocaml/baseline/coin_min.ml b/lib/ocaml/baseline/coin_min.ml new file mode 100644 index 00000000..bbf7c34f --- /dev/null +++ b/lib/ocaml/baseline/coin_min.ml @@ -0,0 +1,16 @@ +let coin_min coins amount = + let dp = Array.make (amount + 1) (-1) in + dp.(0) <- 0; + for i = 1 to amount do + List.iter (fun c -> + if c <= i && dp.(i - c) >= 0 then begin + let cand = dp.(i - c) + 1 in + if dp.(i) < 0 || cand < dp.(i) then dp.(i) <- cand + end + ) coins + done; + dp.(amount) + +;; + +coin_min [1; 5; 10; 25] 67 diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 26f54877..e3b5f06a 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -25,6 +25,7 @@ "catalan.ml": 42, "closures.ml": 315, "coin_change.ml": 6, + "coin_min.ml": 6, "count_change.ml": 406, "count_inversions.ml": 12, "csv.ml": 10, diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index e2a86a11..ed2dd5ae 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,13 @@ _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 — coin_min.ml baseline (minimum-coin change + for 67¢ with US denominations = 6 coins). DP with -1 sentinel + for unreachable values: `dp.(i) := min over coins c of dp.(i-c)+1 + when dp.(i-c) >= 0`. 67 = 25+25+10+5+1+1 = 6 coins. Tests `if + c <= i && dp.(i - c) >= 0 then …` guard short-circuit; without + iter-242 fix the dp.(i-c) read would crash for c > i. 158 + baseline programs total. - 2026-05-10 Phase 5.1 — flood_fill.ml baseline (largest connected component in 5×5 grid = 7). Recursive 4-direction flood from every unvisited 1-cell; bounds check short-circuits before the