Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 28, 2011 03:13
Show Gist options
  • Save jakedobkin/1525993 to your computer and use it in GitHub Desktop.
Save jakedobkin/1525993 to your computer and use it in GitHub Desktop.
Project Euler 81
file = open('matrix.txt','r').readlines()
array = []
for i in range (0,len(file)):
line = file[i].split(',')
array.append(line)
#adding algorithm works backward from next to last row to 0 row
for r in range (79,-1,-1):
for s in range (79,-1,-1):
if r == 79 and s < 79:
array[r][s]=int(array[r][s])+int(array[r][s+1])
if r == 79 and s == 79:
array[r][s]=int(array[r][s])
if r < 79 and s < 79:
array[r][s]=int(array[r][s])+min(int(array[r+1][s]),int(array[r][s+1]))
if r < 79 and s == 79:
array[r][s]=int(array[r][s])+int(array[r+1][s])
print array[0][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment