diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 805525cc..469e8e6c 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -52,6 +52,7 @@ "mutable_record.ml": 10, "option_match.ml": 5, "palindrome.ml": 4, + "paren_depth.ml": 7, "pancake_sort.ml": 910, "pascal.ml": 252, "pi_leibniz.ml": 314, diff --git a/lib/ocaml/baseline/paren_depth.ml b/lib/ocaml/baseline/paren_depth.ml new file mode 100644 index 00000000..41e4648b --- /dev/null +++ b/lib/ocaml/baseline/paren_depth.ml @@ -0,0 +1,15 @@ +let max_depth s = + let d = ref 0 in + let m = ref 0 in + for i = 0 to String.length s - 1 do + if s.[i] = '(' then begin + d := !d + 1; + if !d > !m then m := !d + end + else if s.[i] = ')' then d := !d - 1 + done; + !m + +;; + +max_depth "((1+2)*(3-(4+5)))" + max_depth "(((deep)))" + max_depth "()()()" diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 615a22a8..a02864ac 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,14 @@ _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-09 Phase 5.1 — paren_depth.ml baseline (max paren nesting + depth, 3+3+1 = 7). One-pass walk tracking current depth and a + high-water mark. Tests three inputs: + "((1+2)*(3-(4+5)))" → 3 + "(((deep)))" → 3 + "()()()" → 1 + Sum = 7. Tests for-loop char comparison `s.[i] = '('` and + high-water-mark idiom with two refs. 78 baseline programs total. - 2026-05-09 Phase 5.1 — pancake_sort.ml baseline (in-place pancake sort, 9 flips → 910). Each pass finds the max in [0..size-1], flips it to position 0 (if needed), then flips the size-prefix to