-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_082.py
More file actions
25 lines (22 loc) · 854 Bytes
/
Problem_082.py
File metadata and controls
25 lines (22 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
matrix = []
# Read in stuff
with open("./extra_files/p081_matrix.txt", "r") as file_stream:
while True:
line = file_stream.readline()
if not line:
break
matrix.append(list(map(lambda x: int(x), line.split(","))))
# tuples are (y value, x value, count-up-to)
queue = [(y, 0, 0) for y in range(80)]
matrix_values = [[1000000 for x in range(80)] for y in range(80)]
while len(queue) > 0:
y, x, count = queue.pop(0)
if count + matrix[y][x] < matrix_values[y][x]:
matrix_values[y][x] = count + matrix[y][x]
if y > 0:
queue.insert(0, (y - 1, x, matrix_values[y][x]))
if y < 79:
queue.insert(0, (y + 1, x, matrix_values[y][x]))
if x < 79:
queue.insert(0, (y, x + 1, matrix_values[y][x]))
print(min(list(map(lambda x: x[-1], matrix_values))))