ocaml: phase 5.1 subseq_check.ml baseline (subsequence test, 3/5 yes)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s

Two-pointer walk:

  let is_subseq s t =
    let i = ref 0 in
    let j = ref 0 in
    while !i < n && !j < m do
      if s.[!i] = t.[!j] then i := !i + 1;
      j := !j + 1
    done;
    !i = n

advance i only on match; always advance j. Pattern matches if i
reaches n.

Five test cases:
  'abc'  in 'ahbgdc'    yes
  'axc'  in 'ahbgdc'    no  (no x in t)
  ''     in 'anything'  yes (empty trivially)
  'abc'  in 'abc'       yes
  'abcd' in 'abc'       no  (s longer)
  sum = 3

93 baseline programs total.
This commit is contained in:
2026-05-09 18:49:00 +00:00
parent 17a7a91d73
commit b2ff367c6b
3 changed files with 29 additions and 0 deletions

View File

@@ -79,6 +79,7 @@
"shuffle.ml": 55,
"simpson_int.ml": 10000,
"stable_unique.ml": 46,
"subseq_check.ml": 3,
"subset_sum.ml": 8,
"tic_tac_toe.ml": 1,
"word_freq.ml": 8,

View File

@@ -0,0 +1,18 @@
let is_subseq s t =
let i = ref 0 in
let n = String.length s in
let m = String.length t in
let j = ref 0 in
while !i < n && !j < m do
if s.[!i] = t.[!j] then i := !i + 1;
j := !j + 1
done;
!i = n
;;
(if is_subseq "abc" "ahbgdc" then 1 else 0) +
(if is_subseq "axc" "ahbgdc" then 1 else 0) +
(if is_subseq "" "anything" then 1 else 0) +
(if is_subseq "abc" "abc" then 1 else 0) +
(if is_subseq "abcd" "abc" then 1 else 0)

View File

@@ -407,6 +407,16 @@ _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 — subseq_check.ml baseline (string is
subsequence?, 3/5 yes). Two-pointer walk: advance `i` only on
match, always advance `j`. Match if `i` reaches `n` (consumed
all of s). Five test cases:
abc in ahbgdc yes
axc in ahbgdc no (no x in t)
"" in anything yes (empty trivially)
abc in abc yes
abcd in abc no (s longer)
Sum = 3. 93 baseline programs total.
- 2026-05-09 Phase 5.1 — merge_intervals.ml baseline (LeetCode #56,
total length 9 + 3 = 12). Sort by start, then sweep maintaining a
current `(cs, ce)` window — extend `ce` if next start ≤ ce, else