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