Created
December 29, 2011 16:34
-
-
Save jakedobkin/1534868 to your computer and use it in GitHub Desktop.
Euler 82 - Doesn't Work Yet
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('matrix2.txt','r').readlines() | |
# i thought maybe if we worked the box in two sections- from the top down and from the bottom up | |
# meeting in the middle, where the target cell was- but this doesn't appear to work either | |
array = [] | |
for i in range (0,len(file)): | |
line = file[i].split(',') | |
array.append(line) | |
n = len(array) | |
for y in range (0,n): | |
array = [] | |
for i in range (0,len(file)): | |
line = file[i].split(',') | |
array.append(line) | |
for r in range (0,y+1): | |
for s in range (n-2,-1,-1): | |
if r == 0: | |
array[r][s]=int(array[r][s])+min(int(array[r][s+1]),int(array[r+1][s])) | |
if r == n-1: | |
array[r][s]=int(array[r][s])+min(int(array[r][s+1]),int(array[r-1][s])) | |
if r < n-1 and r > 0: | |
array[r][s]=int(array[r][s])+min(int(array[r+1][s]),int(array[r-1][s]),int(array[r][s+1])) | |
for r in range (n-1,y,-1): | |
for s in range (n-2,-1,-1): | |
if r == 0: | |
array[r][s]=int(array[r][s])+min(int(array[r][s+1]),int(array[r+1][s])) | |
if r == n-1: | |
array[r][s]=int(array[r][s])+min(int(array[r][s+1]),int(array[r-1][s])) | |
if r < n-1 and r > 0: | |
array[r][s]=int(array[r][s])+min(int(array[r+1][s]),int(array[r-1][s]),int(array[r][s+1])) | |
print array[y][0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment