Maximum triangle path sum: Difference between revisions

m
added comments
m (Better use of pattern matching rules to avoid calling tl().)
m (added comments)
Line 984:
end.
 
% The first argument has one more element than the second, so compute
% the initial sum so that both lists have identical length for fold_rest().
fold_row([], L) -> L;
fold_row([A|_] = Last, [B|Bs]) ->
[A+B | fold_rest(Last, Bs)].
 
% Both lists must have same length
fold_rest([A], [B]) -> [A+B];
fold_rest([A1 | [A2|_] = As], [B|Bs]) -> [B + max(A1,A2) | fold_rest(As, Bs)].
357

edits