ocaml: phase 5.1 unique_paths_obs.ml baseline (4x4 grid w/ obstacles = 3)
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
Standard 2D unique-paths DP with obstacles gating each cell:
dp[i][j] = if grid[i][j] = 1 then 0
else dp[i-1][j] + dp[i][j-1]
Grid (1s are obstacles):
. . . .
. # . .
. . . #
# . . .
dp:
1 1 1 1
1 0 1 2
1 1 2 0
0 1 3 3
Returns dp[3][3] = 3.
Complements grid_paths.ml (no-obstacles version) — same DP shape
but obstacles zero out cells and reshape the path count.
199 baseline programs total.
This commit is contained in:
@@ -196,6 +196,7 @@
|
||||
"triangle_div.ml": 120,
|
||||
"twosum.ml": 5,
|
||||
"union_find.ml": 4,
|
||||
"unique_paths_obs.ml": 3,
|
||||
"unique_set.ml": 9,
|
||||
"validate.ml": 417,
|
||||
"word_count.ml": 3
|
||||
|
||||
28
lib/ocaml/baseline/unique_paths_obs.ml
Normal file
28
lib/ocaml/baseline/unique_paths_obs.ml
Normal file
@@ -0,0 +1,28 @@
|
||||
let h = 4
|
||||
let w = 4
|
||||
let grid = [|
|
||||
[| 0; 0; 0; 0 |];
|
||||
[| 0; 1; 0; 0 |];
|
||||
[| 0; 0; 0; 1 |];
|
||||
[| 1; 0; 0; 0 |]
|
||||
|]
|
||||
|
||||
let paths_with_obs () =
|
||||
let dp = Array.init h (fun _ -> Array.make w 0) in
|
||||
if grid.(0).(0) = 0 then dp.(0).(0) <- 1;
|
||||
for j = 1 to w - 1 do
|
||||
if grid.(0).(j) = 0 then dp.(0).(j) <- dp.(0).(j - 1)
|
||||
done;
|
||||
for i = 1 to h - 1 do
|
||||
if grid.(i).(0) = 0 then dp.(i).(0) <- dp.(i - 1).(0)
|
||||
done;
|
||||
for i = 1 to h - 1 do
|
||||
for j = 1 to w - 1 do
|
||||
if grid.(i).(j) = 0 then
|
||||
dp.(i).(j) <- dp.(i - 1).(j) + dp.(i).(j - 1)
|
||||
done
|
||||
done;
|
||||
dp.(h - 1).(w - 1)
|
||||
;;
|
||||
|
||||
paths_with_obs ()
|
||||
@@ -407,6 +407,12 @@ _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 — unique_paths_obs.ml baseline (count
|
||||
monotone paths in 4×4 grid with obstacles at (1,1),(2,3),(3,0)
|
||||
= 3). Standard 2D DP with obstacle gating: dp[i][j] = dp[i-1][j]
|
||||
+ dp[i][j-1] when grid[i][j]=0, else 0. Complements grid_paths.ml
|
||||
(no-obstacles version): the same DP but obstacles zero out
|
||||
cells, reshaping the path count. 199 baseline programs total.
|
||||
- 2026-05-11 Phase 5.1 — daily_temperatures.ml baseline (monotonic
|
||||
decreasing stack of waiting days until warmer; sum over
|
||||
[73;74;75;71;69;72;76;73] = 10). For each day i, pop all stack
|
||||
|
||||
Reference in New Issue
Block a user