ocaml: phase 5.1 gas_station.ml baseline (circular tour start = 3)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Classic O(n) greedy gas-station algorithm:
walk once, tracking
total = sum of (gas[i] - cost[i]) -- if negative, no answer
curr = running tank since start -- on negative, advance
start past i+1 and reset
if total < 0 then -1 else start
For gas = [1;2;3;4;5], cost = [3;4;5;1;2], unique start = 3.
Tests `total` + `curr` parallel accumulators, reset-on-failure
pattern.
202 baseline programs total.
This commit is contained in:
@@ -407,6 +407,14 @@ _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 — gas_station.ml baseline (find unique start
|
||||
station for circular gas tour, gas=[1;2;3;4;5] cost=[3;4;5;1;2]
|
||||
→ start at index 3). Classic O(n) greedy: walk once tracking the
|
||||
total tank delta (if negative, no solution → -1) and a running
|
||||
tank that resets to 0 when it goes negative, advancing start
|
||||
past the failing index. From station 3: tank 3,3+5,3+5−3,…
|
||||
succeeds. Tests `total` + `curr` parallel accumulators, reset-
|
||||
on-failure pattern. 202 baseline programs total.
|
||||
- 2026-05-11 Phase 5.1 — min_jumps.ml baseline (greedy BFS-like
|
||||
min jumps to reach end of [2;3;1;1;2;4;2;0;1;1] = 4). At each
|
||||
position track the farthest reach within the current "BFS
|
||||
|
||||
Reference in New Issue
Block a user