ocaml: phase 5.1 grid_paths.ml baseline (count paths in 4x6 grid = 210)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
DP filling a flattened 2D array: dp.(0, 0) = 1 dp.(i, j) = dp.(i-1, j) + dp.(i, j-1) index = i * (n+1) + j For a 4x6 grid (5x7 dp matrix), the count is C(10, 4) = 210. Tests Array as 2D via row-major flatten + nested for + multi-step conditional access (above/left guarded by 'if i > 0' / 'if j > 0'). 87 baseline programs total.
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
"frequency.ml": 5,
|
"frequency.ml": 5,
|
||||||
"gcd_lcm.ml": 60,
|
"gcd_lcm.ml": 60,
|
||||||
"grep_count.ml": 3,
|
"grep_count.ml": 3,
|
||||||
|
"grid_paths.ml": 210,
|
||||||
"group_consec.ml": 53,
|
"group_consec.ml": 53,
|
||||||
"hailstone.ml": 111,
|
"hailstone.ml": 111,
|
||||||
"hanoi.ml": 1023,
|
"hanoi.ml": 1023,
|
||||||
|
|||||||
17
lib/ocaml/baseline/grid_paths.ml
Normal file
17
lib/ocaml/baseline/grid_paths.ml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
let count_paths m n =
|
||||||
|
let dp = Array.make ((m + 1) * (n + 1)) 0 in
|
||||||
|
dp.(0) <- 1;
|
||||||
|
for i = 0 to m do
|
||||||
|
for j = 0 to n do
|
||||||
|
if i > 0 || j > 0 then begin
|
||||||
|
let above = if i > 0 then dp.((i - 1) * (n + 1) + j) else 0 in
|
||||||
|
let left = if j > 0 then dp.(i * (n + 1) + j - 1) else 0 in
|
||||||
|
dp.(i * (n + 1) + j) <- above + left
|
||||||
|
end
|
||||||
|
done
|
||||||
|
done;
|
||||||
|
dp.(m * (n + 1) + n)
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
count_paths 4 6
|
||||||
@@ -407,6 +407,12 @@ _Newest first._
|
|||||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||||
recursive match, List.append, List.fold_left.
|
recursive match, List.append, List.fold_left.
|
||||||
|
- 2026-05-09 Phase 5.1 — grid_paths.ml baseline (count distinct
|
||||||
|
paths in (4+1)x(6+1) grid = C(10,4) = 210). DP fills a flattened
|
||||||
|
2D array: `dp.(0,0) = 1`, others `dp.(i,j) = dp.(i-1,j) + dp.(i,
|
||||||
|
j-1)`. Index = `i * (n+1) + j`. Tests Array as 2D via row-major
|
||||||
|
flatten + nested for + multi-step conditional access. 87 baseline
|
||||||
|
programs total.
|
||||||
- 2026-05-09 Phase 5.1 — fib_doubling.ml baseline (Fibonacci by
|
- 2026-05-09 Phase 5.1 — fib_doubling.ml baseline (Fibonacci by
|
||||||
doubling, fib(40) = 102334155). Uses the identity F(2k) = F(k) *
|
doubling, fib(40) = 102334155). Uses the identity F(2k) = F(k) *
|
||||||
(2*F(k+1) - F(k)) and F(2k+1) = F(k)^2 + F(k+1)^2 to compute fib
|
(2*F(k+1) - F(k)) and F(2k+1) = F(k)^2 + F(k+1)^2 to compute fib
|
||||||
|
|||||||
Reference in New Issue
Block a user