2017-08-23 17:57:34 +08:00

15 lines
443 B
Python

def get_file(fn):
with open(fn, 'r') as f:
return list(map(lambda x:
list(map(lambda x: int(x), x.split(' '))),
f.read().strip().split('\n')))
def shortest(pick, triangle):
path = triangle.pop(0)
for line in triangle:
path = list(map(lambda x: pick(x[0], x[1]) + x[2], zip(path, path[1:], line)))
return path
print(shortest(max, list(reversed(get_file('../resource/triangle.txt')))))