Skip to content
Snippets Groups Projects
Commit f005f87a authored by Taddeus Kroes's avatar Taddeus Kroes
Browse files

Started working on 82

parent 40eab4bf
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
from copy import deepcopy
m = [map(int, line.split(',')) for line in open('matrix.txt', 'r').readlines()]
h, w = len(m), len(m[0])
orig = deepcopy(m)
def trypath(paths, *indices):
try:
paths.append(sum(orig[y][x] for x, y in indices))
except IndexError:
pass
for c in xrange(1, w):
for r in xrange(h):
paths = []
trypath(paths, (c - 1, r - 1), (c, r - 1))
trypath(paths, (c - 1, r))
trypath(paths, (c - 1, r + 1), (c, r + 1))
m[r][c] += min(paths)
print min(row[-1] for row in m)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment