Commit f005f87a authored by Taddeus Kroes's avatar Taddeus Kroes

Started working on 82

parent 40eab4bf
#!/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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment