Jump to content

Maximum triangle path sum: Difference between revisions

m
Better use of pattern matching rules to avoid calling tl().
(Erlang version)
m (Better use of pattern matching rules to avoid calling tl().)
Line 985:
 
fold_row([], L) -> L;
fold_row([A|_] = Last, [B|_Bs] = Current) ->
[A+B | fold_rest(Last, tl(Current)Bs)].
 
fold_rest([A], [B]) -> [A+B];
fold_rest([A1, | [A2|_] = PrevAs], [B|Bs]) -> [B + max(A1,A2) | fold_rest(tl(Prev)As, Bs)].
</lang>
{{Out}}
357

edits

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