Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 29, 2011 16:34
Show Gist options
  • Save jakedobkin/1534868 to your computer and use it in GitHub Desktop.
Save jakedobkin/1534868 to your computer and use it in GitHub Desktop.
Euler 82 - Doesn't Work Yet
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