22 lines
733 B
Python
22 lines
733 B
Python
with open('./dat/18-6.txt', 'r') as f:
|
|
matrix = [[int(i) for i in e.split()] for e in f.readlines()]
|
|
arr = []
|
|
|
|
for row_index, row in enumerate(matrix):
|
|
new_row = []
|
|
for el_index, el in enumerate(row):
|
|
if row_index == 0 and el_index == 0:
|
|
new_row.append([matrix[0][0]] * 2)
|
|
elif row_index == 0:
|
|
new_row.append([new_row[el_index-1][0] + el] * 2)
|
|
elif el_index == 0:
|
|
new_row.append([arr[row_index-1][el_index][0] + el] * 2)
|
|
else:
|
|
ns = [max([arr[row_index-1][el_index][0], new_row[el_index-1][0]]) + el,
|
|
min([arr[row_index-1][el_index][1], new_row[el_index-1][1]]) + el]
|
|
new_row.append(ns)
|
|
arr.append(new_row)
|
|
|
|
print(arr[-1][-1])
|
|
|
|
# 1418 743 |