Created
December 28, 2011 03:13
-
-
Save jakedobkin/1525993 to your computer and use it in GitHub Desktop.
Project Euler 81
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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