SharedProject Euler / Problem67.ipynbOpen in CoCalc
import numpy as np
T=[]
for line in open('p067_triangle.txt'):
    T.append(np.array([int(v) for v in line.strip().split(" ")]))
S=T
for i in range(1,100):
    S[i][0]=T[i][0]+S[i-1][0]
    if 1<i<100:
        for j in range(1,i):
            S[i][j]=T[i][j]+max(S[i-1][j-1],S[i-1][j])
    S[i][i]=T[i][i]+S[i-1][i-1]
M=S[99][0]
for j in range(1,100):
    M=max(M,S[99][j])
M
7273