## Furkan Emre Işık ## Technical Assignment ## Note before start, There was many better codes on the internet but I wanted to do something by my own instead of copy pasting. ## Best regards, ## Let's get started :) from itertools import combinations f = open(input("Input the text file path: "),"r") ## Text file input input_pyramid = [line.split() for line in f.readlines()] f.close() for x in range(len(input_pyramid)): ## Text file converted to integer list for y in range(len(input_pyramid[x])): input_pyramid[x][y] = int(input_pyramid[x][y]) steps = len(input_pyramid) - 1 sum = input_pyramid[0][0] liste = [] ## Dummy list for possible paths c = [] ## Dummy list of sum if path reaches to bottom m = [] ## Dummy list of sum if path does not reach to bottom b = 0 ## Initializing dummy variables z = 0 ## Initializing dummy variables o = 0 ## Initializing dummy variables for n in range(2, input_pyramid[0][0]): ## Prime check for top element if input_pyramid[0][0] % n == 0: o = 1 if o != 1: print("The top of the pyramid is a PRIME NUMBER!!") exit() for u in range(0, steps): ## Possible paths pushed to list as 1's and 2's (left and right bottom of element) liste.append(1) liste.append(2) comb = combinations(liste, steps) ## Duplicate combinations concatenated comb = list(dict.fromkeys(comb)) for i in comb: z += 1 l = 0 for j in range(steps): f = 0 if i[j] == 2: l += 1 for n in range(2, input_pyramid[j + 1][l]): if input_pyramid[j + 1][l] % n == 0: f = 1 break if f == 1: sum += input_pyramid[j + 1][l] else: break if j == steps-1 and f == 1: m.append(sum) c.append(sum) sum = input_pyramid[0][0] if m == []: ## Print sum if path reaches to bottom print(max(c)) else: print(max(m)) ## Print sum if path does not reach to bottom