diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 81064fe6..16164f52 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -81,6 +81,7 @@ "histogram_area.ml": 10, "huffman.ml": 224, "int_sqrt.ml": 1027, + "interval_overlap.ml": 6, "is_prime.ml": 25, "island_count.ml": 5, "fizz_classifier.ml": 540, diff --git a/lib/ocaml/baseline/interval_overlap.ml b/lib/ocaml/baseline/interval_overlap.ml new file mode 100644 index 00000000..4dabf426 --- /dev/null +++ b/lib/ocaml/baseline/interval_overlap.ml @@ -0,0 +1,16 @@ +let count_overlaps intervals = + let arr = Array.of_list intervals in + let n = Array.length arr in + let count = ref 0 in + for i = 0 to n - 1 do + let (s1, e1) = arr.(i) in + for j = i + 1 to n - 1 do + let (s2, e2) = arr.(j) in + if s1 <= e2 && s2 <= e1 then count := !count + 1 + done + done; + !count + +;; + +count_overlaps [(1, 4); (2, 5); (7, 9); (3, 6); (8, 10); (11, 12); (0, 2)] diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index d2902e4d..8a57b93c 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,15 @@ _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 — interval_overlap.ml baseline (count + overlapping interval pairs in 7-interval set = 6). For each pair + (i, j) test `s1 ≤ e2 && s2 ≤ e1`. Intervals: (1,4) (2,5) (7,9) + (3,6) (8,10) (11,12) (0,2). Overlapping pairs: + (1,4)&(2,5), (1,4)&(3,6), (1,4)&(0,2), + (2,5)&(3,6), (2,5)&(0,2), (7,9)&(8,10) + = 6 pairs. Tests double for-loop with both-side tuple destructure + via `let (s1, e1) = arr.(i) in`, conjunctive comparison, list-to- + array conversion. 188 baseline programs total. - 2026-05-11 Phase 5.1 — count_palindromes.ml baseline (count palindromic substrings of "aabaa" = 9). Expand-around-center with 2n−1 centers (n odd-length, n−1 even-length); for each,