Jump to content

Maximum triangle path sum: Difference between revisions

Line 720:
// (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
function zipWith3(f, xs, ys, zs) {
return zs.length ? [f(xs[0] || [], ys[0] || [], zs[0])].concat(
zipWith3(f, xs.slice(1), ys.slice(1), zs.slice(1))) : [];
}
 
// Evaluating from the bottom row upwards
// with left to right recursion
return foldr1(
function (xs, ys) {
Line 732 ⟶ 730:
return x + (y < z ? z : y);
},
xs, ys, ys.slice(1) // item above, and larger of two below
);
}, [
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.