-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem67.py
36 lines (24 loc) · 847 Bytes
/
problem67.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def readInPyramid(fileName):
file = open(fileName)
line = file.readline()
pyramid = []
count = 0
while line:
pyramid.append([])
numbers = line.split()
for n in numbers:
pyramid[count].append(int(n))
count += 1
line = file.readline()
return pyramid
if __name__ == '__main__':
pyramid = readInPyramid('/Users/matt/PycharmProjects/pyramid2.txt')
# pyramid = readInPyramid('/Users/matt/PycharmProjects/practice_pyramid.txt')
height = len(pyramid)
print(height)
for row in range(1, height):
pyramid[row][0] += pyramid[row-1][0]
pyramid[row][row] += pyramid[row-1][row-1]
for index in range(1, row):
pyramid[row][index] += max(pyramid[row-1][index-1], pyramid[row-1][index])
print(max(pyramid[height-1]))