Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Project Euler Problem 67
# Read the problem matrix into a triangle array in python
filename = 'euler67.txt'
with open(filename, "r") as ins:
array = []
for line in ins:
# Convert the triangle arry entries into integers
newArray = []
for i in array:
j = i.split(' ')
k = [int(n) for n in j]
l = len(newArray)
# Algorithm to calculate Maximum Path Sum
for i in range(l-1):
array1 = newArray[-1]
array2 = newArray[-2]
for j in range(len(array2)):
array2[j] += max(array1[j], array1[j+1])
newArray[-1] = array2
print newArray[0][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment