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:
@@ -74,6 +74,7 @@
|
||||
"fib_mod.ml": 391360,
|
||||
"fraction.ml": 7,
|
||||
"frequency.ml": 5,
|
||||
"gas_station.ml": 3,
|
||||
"gcd_lcm.ml": 60,
|
||||
"gray_code.ml": 136,
|
||||
"grep_count.ml": 3,
|
||||
|
||||
Reference in New Issue
Block a user