I am trying to solve project euler problem 18.
http://projecteuler.net/problem=18
I tried a greedy algorithm with python working from the bottom of the triangle.
THen I move up one row and find the biggest route with a greedy algorithm and try to connect the biggest route but it doesn’t work. DO you have any hints that would put me on the right track without giving the solution of the problem away.
here is the function:
def greedy(i):
if i%15==0:
a=[(b[i-15],i-15),(b[i-14],i-14)]
a=sorted(a)
a=a[-1]
else:
a=[(b[i-15],i-15),(b[i-16],i-16),(b[i-14],i-14)]
a=sorted(a)
a=a[-1]
return a
Cheers
Have you ever heard of Dynamic Programming?
Consider this problem. What makes a route the best? Is there any relation between the last step and the previous ones? Also, look at this triangle where the greedy algorithm doesn’t give you the right answer: