Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -1,14 +1,17 @@
'''Maximum triangle path sum'''
from functools import (reduce)
from itertools import (starmap)
# maxPathSum :: [[Int]] -> Int
def maxPathSum(rows):
'''The maximum total among all possible
paths from the top to the bottom row.
'''
return reduce(
lambda xs, ys: list(starmap(
lambda a, b, c: a + max(b, c),
zip(ys, xs, xs[1:])
)),
lambda xs, ys: [
a + max(b, c) for (a, b, c) in zip(ys, xs, xs[1:])
],
reversed(rows[:-1]), rows[-1]
)[0]