def notPrime(num): if num <= 2 : return False for i in range(2,(num)): if num % i == 0: return True return False def maxPathSum(pyramid, m, n): for i in range(m-1, -1, -1): for j in range(i+1): if (pyramid[i+1][j] > pyramid[i+1][j+1]): pyramid[i][j] += pyramid[i+1][j] else: pyramid[i][j] += pyramid[i+1][j+1] return pyramid[0][0] def solve(pyramid,row,col,score): if row == len(pyramid)-1: return score else: if solve(pyramid,row+1,col,score+pyramid[row+1][col]) > solve(pyramid,row+1,col+1,score+pyramid[row+1][col+1]): return solve(pyramid,row+1,col,score+pyramid[row+1][col]) else: return solve(pyramid,row+1,col+1,score+pyramid[row+1][col+1]) file = open("test.txt","r") pyramid = [] count = 0 while True: data = file.readline().split() if not data: file.close() break pyramid.append(data) for row in pyramid: for i in range(len(row)): row[i] = int(row[i]) for row in pyramid: for num in range(len(pyramid[-1])-len(row)): row.append(0) for i in range(len(pyramid)): for j in range(len(pyramid)): if pyramid[i][j] == 0: continue if not notPrime(pyramid[i][j]): pyramid[i][j] = 0 len_row = len(pyramid) len_col = len(pyramid[0]) print(solve(pyramid,0,0,0))