def not_prime(num):
is_prime(num):
if num == 1:
return False
if num == 2:
return True
if num > 1:
2:
# check for factors
factors
for i in range(2,num):
range(2, num):
if (num % i) == 0:
0:
return True
print(i,"times",num//i,"is",num)
break
else:
False
return False
True
# if input number is less than
# or equal to 1, it is not prime
else:
return True
True
def maxPathSum(tree, primeRemover(tri, m, n):
# loop for bottom-up calculation
n):
for i in range(m-1, -1, -1):
range(0, m+1):
for j in range(i+1):
range(0, n+1):
if (tri[i+1][j] > tri[i+1][j+1] and not_prime(tri[i+1][j])):
is_prime(tri[i][j]):
tri[i][j] += tri[i+1][j]
elif not_prime(tri[i+1][j+1]):
tri[i][j] += tri[i+1][j+1]
= 0
print(tri)
return tri[0][0]
tri = [[1,0,0,0],
[8,4,0,0],
[2,6,9,0],
[8,5,9,3]]
print maxPathSum(tree, 3, 3)tri
Replies to developer
Title |
Name |
Language |
UNIX |
When |
developer |
Sohrab Yavarzadeh |
python |
1591812813 |
3 Years ago. |
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}