Skip to content

Commit

Permalink
Add 067 with list comprehension to read triangle file (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranisalt authored Oct 1, 2021
1 parent 8b233dc commit 388bb67
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions euler0XX/euler067-comprehension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
with open('euler067_triangle.txt') as fp:
triangle = [[int(n) for n in line.split(' ')] for line in fp]

def maximize(triangle):
triangle = triangle[:]
for i in range(len(triangle) - 2, -1, -1):
for j, value in enumerate(triangle[i]):
triangle[i][j] = value + max(triangle[i + 1][j:j + 2])
return triangle[0][0]

print(maximize(triangle))

0 comments on commit 388bb67

Please sign in to comment.