Two-pointer merge advancing the smaller-head pointer k times,
without materializing the merged array:
while !count < k do
let pick_a =
if !i = m then false (* a exhausted, take from b *)
else if !j = n then true (* b exhausted, take from a *)
else a.(!i) <= b.(!j)
in
if pick_a then ... else ...;
count := !count + 1
done
For a = [1;3;5;7;9;11;13], b = [2;4;6;8;10;12]:
merged order: 1,2,3,4,5,6,7,8,9,10,11,12,13
8th element = 8.
Tests nested if/else if/else flowing into a bool, dual-ref
two-pointer loop, separate count counter for k-th constraint.
184 baseline programs total.
Recursive permutation generator via fold-pick-recurse:
let rec permutations xs = match xs with
| [] -> [[]]
| _ ->
List.fold_left (fun acc x ->
let rest = List.filter (fun y -> y <> x) xs in
let subs = permutations rest in
acc @ List.map (fun p -> x :: p) subs
) [] xs
For permutations of [1; 2; 3; 4] (24 total), count those whose
first element is less than the last:
match p with
| [a; _; _; b] when a < b -> count := !count + 1
| _ -> ()
By symmetry, exactly half satisfy a < b = 12.
Tests List.filter, recursive fold with append, fixed-length
list pattern [a; _; _; b] with multiple wildcards + when guard.
183 baseline programs total.
Recursive regex matcher with Leetcode-style semantics:
. matches any single character
<c>* matches zero or more of <c>
let rec is_match s i p j =
if j = String.length p then i = String.length s
else
let first = i < String.length s
&& (p.[j] = '.' || p.[j] = s.[i])
in
if j + 1 < String.length p && p.[j+1] = '*' then
is_match s i p (j + 2) (* skip * group *)
|| (first && is_match s (i + 1) p j) (* consume one *)
else
first && is_match s (i + 1) p (j + 1)
Patterns vs texts:
.a.b | aabb axb "" abcd abc aaabbbc x -> 1 match
a.*b | aabb axb "" abcd abc aaabbbc x -> 2 matches
x* | aabb axb "" abcd abc aaabbbc x -> 2 matches
a*b*c | aabb axb "" abcd abc aaabbbc x -> 2 matches
total = 7
Complements wildcard_match.ml which uses LIKE-style * / ?.
182 baseline programs total.
Two-phase palindrome-partition DP for the minimum-cuts variant:
Phase 1: is_pal[i][j] palindrome table via length-major fill
(single chars, then pairs, then expand inward).
Phase 2: cuts[i] = 0 if s[0..i] is itself a palindrome,
= min over j of (cuts[j-1] + 1)
where s[j..i] is a palindrome.
min_cut "aabba" = 1 ("a" | "abba")
Tests two sequential 2D DPs sharing the same is_pal matrix,
inline begin/end branches inside the length-major fill, mixed
bool and int 2D arrays.
181 baseline programs total.
Classic word-break DP — for each position i, check whether any
dictionary word ends at i with a prior reachable position:
dp[i] = exists w in dict with wl <= i and
dp[i - wl] && s.sub (i - wl) wl = w
Dictionary: apple, pen, pine, pineapple, cats, cat, and, sand, dog
Inputs:
applepenapple yes (apple pen apple)
pineapplepenapple yes (pineapple pen apple)
catsanddog yes (cats and dog)
catsandog no (no segmentation reaches the end)
applesand yes (apple sand)
Tests bool-typed Array, String.sub primitive, nested List.iter
over the dict inside for-loop over end positions, closure capture
of the outer dp.
179 baseline programs total.
Linear-time stack algorithm for largest rectangle in histogram:
for i = 0 to n do
let h = if i = n then 0 else heights.(i) in
while top-of-stack's height > h do
pop the top, compute its max-width rectangle:
width = (no-stack ? i : i - prev_top - 1)
area = height * width
update best
done;
if i < n then push i
done
Sentinel pass at i=n with h=0 flushes the remaining stack.
For [2; 1; 5; 6; 2; 3], bars at indices 2 (h=5) and 3 (h=6) form
a width-2 rectangle of height 5 = 10.
Tests guarded patterns with `when` inside while-cont-flag, nested
`match !stack with | [] -> i | t :: _ -> i - t - 1` for width
computation.
178 baseline programs total.
Standard O(n^2) length-major DP for longest palindromic
subsequence:
dp[i][j] = dp[i+1][j-1] + 2 if s[i] = s[j]
= max(dp[i+1][j], dp[i][j-1]) otherwise
lps "BBABCBCAB" = 7 (witness "BABCBAB" etc.)
Complementary to manacher.ml (longest palindromic *substring*,
also length 7 on that input by coincidence) — this is the
subsequence variant which doesn't require contiguity.
Tests length-major fill order, inline if for the length-2 base
case, double-nested for with derived j = i + len - 1.
177 baseline programs total.
Classic distinct-subsequences 2D DP:
dp[i][j] = dp[i-1][j] + (s[i-1] = t[j-1] ? dp[i-1][j-1] : 0)
dp[i][0] = 1 (empty t is a subseq of any prefix of s)
count_subseq "rabbbit" "rabbit" = 3
The three witnesses correspond to which 'b' in "rabbbit" is
dropped (positions 2, 3, or 4 zero-indexed of the run of bs).
Complements subseq_check.ml (just tests presence); this one counts
distinct embeddings.
Tests 2D DP with Array.init n (fun _ -> Array.make m 0), base row
initialization, mixed string + array indexing.
175 baseline programs total.
Stack-based multi-bracket parenthesis matching for ( [ { ) ] }.
Non-bracket chars are skipped (treated as content).
Tests:
() yes
[{()}] yes
({[}]) no (mismatched closer)
"" yes
(( no (unclosed)
()[](){} yes
(a(b)c) yes (a/b/c skipped)
(() no
]) no
5 balanced
Body uses begin/end-wrapped match inside while:
else if c = ')' || c = ']' || c = '}' then begin
match !stack with
| [] -> ok := false
| top :: rest ->
let pair =
(c = ')' && top = '(') ||
(c = ']' && top = '[') ||
(c = '}' && top = '{')
in
if pair then stack := rest else ok := false
end
Tests side-effecting match arms inside while body, ref-of-list as
stack, multi-char pairing dispatch.
174 baseline programs total.
Recursive wildcard matcher:
let rec is_match s i p j =
if j = String.length p then i = String.length s
else if p.[j] = '*' then
is_match s i p (j + 1) (* * matches empty *)
|| (i < String.length s && is_match s (i + 1) p j) (* * eats char *)
else
i < String.length s
&& (p.[j] = '?' || p.[j] = s.[i])
&& is_match s (i + 1) p (j + 1)
Patterns vs texts:
a*b | aaab abc abxyz xy xyz axby -> 1 match
?b*c | aaab abc abxyz xy xyz axby -> 1 match
*x*y* | aaab abc abxyz xy xyz axby -> 4 matches
total = 6
Tests deeply nested short-circuit && / ||, char equality on
pattern bytes, doubly-nested List.iter cross product.
173 baseline programs total.
Recursive powerset construction by doubling:
let rec gen xs = match xs with
| [] -> [[]]
| h :: rest ->
let sub = gen rest in
sub @ List.map (fun s -> h :: s) sub
Enumerates all 2^10 = 1024 subsets, filters by sum:
count = |{ S ⊆ {1..10} | Σ S = 15 }| = 20
Examples: {1,2,3,4,5}, {2,3,4,6}, {1,4,10}, {7,8}, {6,9}, ...
Tests recursive subset construction via List.map + closures,
pattern matching with h :: rest, List.fold_left (+) 0 sum reduce,
exhaustive O(2^n * n) traversal.
172 baseline programs total.
Real OCaml accepts `match e1, e2 with | p1, p2 -> …` without
surrounding parens. parse-pattern previously stopped at the cons
layer (`p :: rest`) and treated a trailing `,` as a separator
the outer caller couldn't handle, surfacing as
"expected op -> got op ,".
Fix: `parse-pattern` now collects comma-separated patterns into a
:ptuple after parse-pattern-cons, before the optional `as` alias.
The scrutinee side already built tuples via parse-tuple, so both
sides are now symmetric.
lru_cache.ml (iter 258) reverts its workaround back to the natural
form:
let rec take n lst = match n, lst with
| 0, _ -> []
| _, [] -> []
| _, h :: r -> h :: take (n - 1) r
607/607 regressions clean.
Functional LRU cache via association-list ordered most-recent-first.
Get / put both:
- find or remove the existing entry
- cons the fresh (k, v) to the front
- on put, trim the tail when over capacity
Sequence:
put 1 100; put 2 200; put 3 300
a = get 1 -> 100 (moves 1 to front)
put 4 400 (evicts 2)
b = get 2 -> -1 (no longer cached)
c = get 3 -> 300
d = get 1 -> 100
a + b + c + d = 499
Tests `match … with (k', v) :: rest when k' = k -> …` tuple-cons
patterns with `when` guards, `function` keyword for arg-less
match, recursive find/remove/take over the same list.
Parser limit found: `match n, lst with` ad-hoc tuple-scrutinee is
not yet supported (got "expected op -> got op ,"); workaround
uses outer `if` plus inner match.
171 baseline programs total.
Fenwick / Binary Indexed Tree for prefix sums. The classic
`i & -i` low-bit trick needs negative-aware AND, but our `land`
evaluator (iter 127, bitwise via floor/mod arithmetic) only handles
non-negative operands. Workaround: a portable lowbit helper that
finds the largest power of 2 dividing i:
let lowbit i =
let r = ref 1 in
while !r * 2 <= i && i mod (!r * 2) = 0 do
r := !r * 2
done;
!r
After building from [1;3;5;7;9;11;13;15]:
total = prefix_sum 8 = 64
update 1 by +100
after = prefix_sum 8 = 164
total + after = 228
Tests recursive update / prefix_sum chains via helper-extracted
lowbit; documents a non-obvious limit of the bitwise-emulation
layer.
168 baseline programs total.
Siamese construction for odd-order magic squares:
- place 1 at (0, n/2)
- for k = 2..n^2, move up-right with (x-1+n) mod n wrap
- if the target cell is taken, drop down one row instead
for n=5, magic constant = n*(n^2+1)/2 = 5*26/2 = 65
Returns the main-diagonal sum (65 by construction).
Tests 2D array via Array.init + Array.make, mod arithmetic with
the (x-1+n) mod n idiom for negative-safe wrap, nested begin/end
branches inside for-loop body.
166 baseline programs total.
Fibonacci via repeated-squaring matrix exponentiation:
[[1, 1], [1, 0]] ^ n = [[F(n+1), F(n)], [F(n), F(n-1)]]
Recursive O(log n) power:
let rec mpow m n =
if n = 0 then identity
else if n mod 2 = 0 then let h = mpow m (n / 2) in mul h h
else mul m (mpow m (n - 1))
Returns the .b cell after raising to the 30th power -> 832040 = F(30).
Tests record literal construction inside recursive function returns,
record field access (x.a etc), and pure integer arithmetic in the
matrix multiply.
165 baseline programs total.
Classic egg-drop puzzle DP:
dp[e][f] = 1 + min over k in [1, f] of
max(dp[e-1][k-1], dp[e][f-k])
For 2 eggs over 36 floors, the optimal worst-case is 8 trials
(closed form: triangular number bound).
Tests 2D DP with triple-nested for-loops, max-of-two via inline
if, large sentinel constant (100000000), mixed shifted indexing
(e-1) and (f-k) where both shift independently.
163 baseline programs total.
DFS topological sort — recurse on out-edges first, prepend after:
let rec dfs v =
if not visited.(v) then begin
visited.(v) <- true;
List.iter dfs adj.(v);
order := v :: !order
end
Same 6-node DAG as iter 230's Kahn's-algorithm baseline:
0 -> {1, 2}
1 -> {3}
2 -> {3, 4}
3 -> {5}
4 -> {5}
5
DFS order: [0; 2; 4; 1; 3; 5]
Horner fold: 0->0->2->24->241->2413->24135.
Complementary to topo_sort.ml (Kahn's BFS); tests recursive DFS
with no explicit stack + List.fold_left as a horner reduction.
160 baseline programs total.
LSD radix sort over base 10 digits. Per pass:
- 10 bucket-refs created via Array.init 10 (fun _ -> ref []) (each
closure call yields a distinct list cell)
- scan array, append each value to its digit's bucket
- flatten buckets back to the array in order
Input [170;45;75;90;802;24;2;66]
Output [2;24;45;66;75;90;170;802]
Sentinel: a.(0) + a.(7)*1000 = 2 + 802*1000 = 802002.
Tests array-of-refs with !buckets.(d) deref, list-mode bucket
sort within in-place array sort, unused for-loop var (`for _ =
1 to maxd`).
159 baseline programs total.
Minimum-coin DP with -1 sentinel for unreachable values:
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 = 6 (* 25+25+10+5+1+1 *)
Tests `if c <= i && dp.(i-c) >= 0 then` short-circuit guard;
relies on iter-242 fix so dp.(i-c) is not evaluated when c > i.
158 baseline programs total.
Recursive 4-way flood fill from every unvisited 1-cell:
let rec flood visited r c =
if r < 0 || r >= h || c < 0 || c >= w then 0
else if visited.(r).(c) || grid.(r).(c) = 0 then 0
else begin
visited.(r).(c) <- true;
1 + flood visited (r - 1) c
+ flood visited (r + 1) c
+ flood visited r (c - 1)
+ flood visited r (c + 1)
end
Grid (1s shown as #, 0s as .):
# # . # #
# . . . #
. . # . .
# # # # .
. . . # #
Largest component: {(2,2),(3,0),(3,1),(3,2),(3,3),(4,3),(4,4)} = 7.
Bounds check r >= 0 must short-circuit before visited/grid reads;
relies on the && / || fix from iter 242.
157 baseline programs total.
Standard in-place next-permutation (Narayana's algorithm):
let next_perm a =
let n = Array.length a in
let i = ref (n - 2) in
while !i >= 0 && a.(!i) >= a.(!i + 1) do i := !i - 1 done;
if !i < 0 then false
else begin
let j = ref (n - 1) in
while a.(!j) <= a.(!i) do j := !j - 1 done;
swap a.(!i) a.(!j);
reverse a (!i + 1) (n - 1);
true
end
Starting from [1;2;3;4;5], next_perm returns true 119 times then
false (when reverse-sorted). 5! - 1 = 119.
Tests guarded `while … && a.(!i) … do` loops that rely on the
iter-242 short-circuit fix.
156 baseline programs total.
Before: `:op` handler always evaluated both operands before dispatching
to ocaml-eval-op. For pure binops that's fine, but `&&` / `||` MUST
short-circuit:
if nr >= 0 && grid.(nr).(nc) = 0 then ...
When nr = -1, real OCaml never evaluates `grid.(-1)`. Our evaluator
did, and crashed with "nth: list/string and number".
Fix: special-case `&&` and `||` in :op dispatch, mirroring the same
pattern already used for `:=` and `<-`. Evaluate lhs, branch on it,
and only evaluate rhs when needed.
Latent since baseline 1 — earlier programs never triggered it because
the rhs was unconditionally safe.
bfs_grid.ml: shortest path through a 5x5 grid with walls. Standard
BFS using Queue.{push,pop,is_empty} + Array.init for the 2D distance
matrix. Path 0,0 -> ... -> 4,4 has length 8. 155 baseline programs
total.
Iterative Levenshtein DP with rolling 1D arrays for O(min(m,n))
space. Distances:
kitten -> sitting : 3
saturday -> sunday : 3
abc -> abc : 0
"" -> abcde : 5
intention -> execution : 5
----------------------------
total : 16
Complementary to the existing levenshtein.ml which uses the
exponential recursive form (only sums tiny strings); this one is
the practical iterative variant used for real ED.
Tests the recently-fixed <- with bare `if` rhs:
curr.(j) <- (if m1 < c then m1 else c) + 1
153 baseline programs total.
Array-backed binary min-heap with explicit size tracking via ref:
let push a size x =
a.(!size) <- x; size := !size + 1; sift_up a (!size - 1)
let pop a size =
let m = a.(0) in
size := !size - 1;
a.(0) <- a.(!size);
sift_down a !size 0;
m
Push [9;4;7;1;8;3;5;2;6], pop nine times -> 1,2,3,4,5,6,7,8,9.
Fold-as-decimal: ((((((((1*10+2)*10+3)*10+4)*10+5)*10+6)*10+7)*10+8)*10+9 = 123456789.
Tests recursive sift_up + sift_down, in-place array swap,
parent/lchild/rchild index arithmetic, combined push/pop session
with refs.
152 baseline programs total.
Polynomial rolling hash mod 1000003 with base 257:
- precompute base^(m-1)
- slide window updating hash in O(1) per step
- verify hash match with O(m) memcmp to skip false positives
rolling_match "abcabcabcabcabcabc" "abc" = 6
Six non-overlapping copies of "abc" at positions 0,3,6,9,12,15.
Tests `for _ = 0 to m - 2 do … done` unused loop variable
(uses underscore wildcard pattern), Char.code arithmetic, mod
arithmetic with intermediate negative subtractions, complex nested
if/begin branching with inner break-via-flag.
151 baseline programs total.
Classic CLRS Huffman code example. ADT:
type tree = Leaf of int * char | Node of int * tree * tree
Build by repeatedly merging two lightest trees (sorted-list pq):
let rec build_tree lst = match lst with
| [t] -> t
| a :: b :: rest ->
let merged = Node (weight a + weight b, a, b) in
build_tree (insert merged rest)
weighted path length (= total Huffman bits):
leaves {(5,a) (9,b) (12,c) (13,d) (16,e) (45,f)} -> 224
Tests sum-typed ADT with mixed arities, `function` keyword
pattern matching, recursive sorted insert, depth-counting recursion.
150 baseline programs total.
Previously `a.(i) <- if c then x else y` failed with
"unexpected token keyword if" because parse-binop-rhs called
parse-prefix for the rhs, which doesn't accept if/match/let/fun.
Real OCaml allows full expressions on the rhs of <-/:=. Fix:
special-case prec-1 ops in parse-binop-rhs to call parse-expr-no-seq
instead of parse-prefix. The recursive parse-binop-rhs with
min-prec restored after picks up any further chained <- (since both
ops are right-associative with no higher-prec binops above them).
Manacher baseline updated to use bare `if` on rhs of <-,
removing the parens workaround from iter 235. 607/607 regressions
remain clean.
Manacher's algorithm: insert # separators (length 2n+1) to unify
odd/even cases, then maintain palindrome radii p[] alongside a
running (center, right) pair to skip work via mirror reflection.
Linear time.
manacher "babadaba" = 7 (* witness: "abadaba", positions 1..7 *)
Note: requires parenthesizing the if-expression on the rhs of <-:
p.(i) <- (if pm < v then pm else v)
Real OCaml parses bare `if` at <-rhs since the rhs is at expr
level; our parser places <-rhs at binop level which doesn't include
`if` / `match` / `let`. Workaround until we relax the binop
RHS grammar.
149 baseline programs total.
Floyd-Warshall all-pairs shortest path with triple-nested for-loop:
for k = 0 to n - 1 do
for i = 0 to n - 1 do
for j = 0 to n - 1 do
if d.(i).(k) + d.(k).(j) < d.(i).(j) then
d.(i).(j) <- d.(i).(k) + d.(k).(j)
done
done
done
Graph (4 nodes, directed):
0->1 weight 5, 0->3 weight 10, 1->2 weight 3, 2->3 weight 1
Direct edge 0->3 = 10, but path 0->1->2->3 = 5+3+1 = 9.
Tests 2D array via Array.init with closure, nested .(i).(j) read
+ write, triple-nested for, in-place mutation under aliasing.
148 baseline programs total.
Modified merge sort that counts inversions during the merge step:
when an element from the right half is selected, the remaining
elements of the left half (mid - i + 1) all form inversions with
that right element.
count_inv [|8; 4; 2; 1; 3; 5; 7; 6|] = 12
Inversions of [8;4;2;1;3;5;7;6]:
with 8: (8,4)(8,2)(8,1)(8,3)(8,5)(8,7)(8,6) = 7
with 4: (4,2)(4,1)(4,3) = 3
with 2: (2,1) = 1
with 7: (7,6) = 1
total = 12
Tests: let rec ... and ... mutual recursion, while + ref + array
mutation, in-place sort with auxiliary scratch array.
145 baseline programs total.
Kahn's algorithm BFS topological sort:
let topo_sort n adj =
let in_deg = Array.make n 0 in
for i = 0 to n - 1 do
List.iter (fun j -> in_deg.(j) <- in_deg.(j) + 1) adj.(i)
done;
let q = Queue.create () in
for i = 0 to n - 1 do
if in_deg.(i) = 0 then Queue.push i q
done;
let count = ref 0 in
while not (Queue.is_empty q) do
let u = Queue.pop q in
count := !count + 1;
List.iter (fun v ->
in_deg.(v) <- in_deg.(v) - 1;
if in_deg.(v) = 0 then Queue.push v q
) adj.(u)
done;
!count
Graph: 0->{1,2}; 1->{3}; 2->{3,4}; 3->{5}; 4->{5}; 5.
Acyclic, so all 6 nodes can be ordered.
Tests Queue.{create,push,pop,is_empty}, mutable array via closure.
144 baseline programs total.
Standard 1D 0/1 knapsack DP with reverse inner loop:
let knapsack values weights cap =
let n = Array.length values in
let dp = Array.make (cap + 1) 0 in
for i = 0 to n - 1 do
let v = values.(i) and w = weights.(i) in
for c = cap downto w do
let take = dp.(c - w) + v in
if take > dp.(c) then dp.(c) <- take
done
done;
dp.(cap)
values: [|6; 10; 12; 15; 20|]
weights: [|1; 2; 3; 4; 5|]
knapsack v w 8 = 36 (* take items with weights 1, 2, 5 *)
Tests for-downto + array literal access in the same hot loop.
143 baseline programs total.
Classic 2D DP for longest common subsequence, optimized to use
two rolling 1D arrays (prev / curr) for O(min(m,n)) space:
for i = 1 to m do
for j = 1 to n do
if s1.[i-1] = s2.[j-1] then curr.(j) <- prev.(j-1) + 1
else if prev.(j) >= curr.(j-1) then curr.(j) <- prev.(j)
else curr.(j) <- curr.(j-1)
done;
for j = 0 to n do prev.(j) <- curr.(j) done
done;
prev.(n)
lcs "ABCBDAB" "BDCAB" = 4
Two valid LCS witnesses: BCAB and BDAB.
Avoids Array.make_matrix (not in our runtime) by manual rolling.
142 baseline programs total.
Disjoint-set union with path compression:
let make_uf n = Array.init n (fun i -> i)
let rec find p x =
if p.(x) = x then x
else begin let r = find p p.(x) in p.(x) <- r; r end
let union p x y =
let rx = find p x in let ry = find p y in
if rx <> ry then p.(rx) <- ry
After unioning (0,1), (2,3), (4,5), (6,7), (0,2), (4,6):
{0,1,2,3} {4,5,6,7} {8} {9} --> 4 components.
Tests Array.init with closure, recursive find, in-place .(i)<-r.
139 baseline programs total.
Hoare quickselect with Lomuto partition: recursively narrows the
range to whichever side contains the kth index. Mutates the array
in place via .(i)<-v. The median (k=4) of [7;2;9;1;5;6;3;8;4] is 5.
let rec quickselect arr lo hi k =
if lo = hi then arr.(lo)
else begin
let pivot = arr.(hi) in
let i = ref lo in
for j = lo to hi - 1 do
if arr.(j) < pivot then begin
let t = arr.(!i) in
arr.(!i) <- arr.(j); arr.(j) <- t;
i := !i + 1
end
done;
...
end
Exercises array literal syntax + in-place mutation in the same
program, ensuring [|...|] yields a mutable backing.
138 baseline programs total.
Added parser support for OCaml array literal syntax:
[| e1; e2; ...; en |] --> Array.of_list [e1; e2; ...; en]
[||] --> Array.of_list []
Desugaring keeps the array representation unchanged (ref-of-list)
since Array.of_list is a no-op constructor for that backing.
Tokenizer emits [, |, |, ] as separate ops; parser detects [ followed
by | and enters array-literal mode, terminating on |].
Baseline lis.ml exercises the syntax:
let lis arr =
let n = Array.length arr in
let dp = Array.make n 1 in
for i = 1 to n - 1 do
for j = 0 to i - 1 do
if arr.(j) < arr.(i) && dp.(j) + 1 > dp.(i) then
dp.(i) <- dp.(j) + 1
done
done;
let best = ref 0 in
for i = 0 to n - 1 do
if dp.(i) > !best then best := dp.(i)
done;
!best
lis [|10; 22; 9; 33; 21; 50; 41; 60; 80|] = 6
137 baseline programs total.