ocaml: phase 5.1 triangle.ml baseline (Pascal-shape min path sum, 2+3+5+1 = 11)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s

Bottom-up DP minimum-path through a triangle:

       2
      3 4
     6 5 7
    4 1 8 3

  let min_path_triangle rows =
    initialise dp from last row;
    for r = n - 2 downto 0 do
      for c = 0 to row_len - 1 do
        dp.(c) <- row.(c) + min(dp.(c), dp.(c+1))
      done
    done;
    dp.(0)

The optimal path 2 -> 3 -> 5 -> 1 sums to 11.

Tests downto loop, Array.of_list inside loop body, nested arr.(i)
reads + writes, and inline if-then-else for min.

74 baseline programs total.
This commit is contained in:
2026-05-09 15:32:11 +00:00
parent a3a93c20b8
commit 5b38f4d499
3 changed files with 29 additions and 0 deletions

View File

@@ -407,6 +407,17 @@ _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 — triangle.ml baseline (Pascal-shape min path
sum, 2+3+5+1 = 11). Bottom-up DP over the triangle:
2
3 4
6 5 7
4 1 8 3
Initialise dp from last row, then for each row above, replace
dp.(c) with row.(c) + min(dp.(c), dp.(c+1)). Final answer in
dp.(0). Tests downto loop, Array.of_list inside loop, nested
arr.(i) reads + writes, and List.nth iteration. 74 baseline
programs total.
- 2026-05-09 Phase 5.1 — max_path_tree.ml baseline (max root-to-leaf
sum in a binary tree, 1+3+7 = 11). Recursive ADT `tree = Leaf |
Node of int * tree * tree`. max_path returns 0 at Leaf, else