Skip to content

Instantly share code, notes, and snippets.

@mavant
Created November 22, 2013 00:29
Show Gist options
  • Save mavant/7592554 to your computer and use it in GitHub Desktop.
Save mavant/7592554 to your computer and use it in GitHub Desktop.
Project Euler problem 67
import operator, csv
pyramid = []
with open ('triangle.txt', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter='\n')
for row in reader:
temp = row[0].split()
for x in range(len(temp)):
temp[x]=int(temp[x])
pyramid.append(temp)
sums = [0]*len(pyramid)
maxpath = 0
for row in reversed(pyramid):
row = map (operator.add, row, sums)
sums = []
a = row.pop()
while (row):
b = row.pop();
sums.append(max(a, b))
a = b
sums.reverse()
maxpath = a
print (maxpath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment