Hey! So I am having trouble with this problem!
Basically you have to find the path that gives the largest sum down this tree:

                        75
                      95 64
                    17 47 82
                  18 35 87 10
                 20 04 82 47 65
               19 01 23 75 03 34
              88 02 77 73 07 63 67
             99 65 04 28 06 16 70 92
            41 41 26 56 83 40 80 70 33
           41 48 72 33 47 32 37 16 94 29
          53 71 44 65 25 43 91 52 97 51 14
         70 11 33 28 77 73 17 78 39 68 17 57
       91 71 52 38 17 14 91 43 58 50 27 29 48
      63 66 04 68 89 53 67 30 73 16 69 87 40 31
     04 62 98 27 23 09 70 98 73 93 38 53 60 04 23

     //Might be easier to look at the actual site, the formatting here is atrocious.

So the problem I'm having is that I have a program that produces a sum. Which when i check by hand should give the right answer, but doesn't. I don't know what's wrong, and im starting to think that I might have misunderstood the question.
I don't want to publish the code as it's horribly messy and could be spoilers for anyone wanting to solve it themselves. The idea though is that, starting from the root, you look at the right and left childnode pick the larger one go to that node and rinse and repeat. The output of my program is:

FORMAT:
Number picked on this line
Line number: Actual Line

Output:
75
Line 1: 75
95
Line 2 : 95 64
47
Line 3 : 17 47 82
87
Line 4 : 18 35 87 10
82
Line 5 : 20 04 82 47 65
75
Line 6 : 19 01 23 75 03 34
73
Line 7 : 88 02 77 73 07 63 67
28
Line 8 : 99 65 04 28 06 16 70 92
83
Line 9 : 41 41 26 56 83 40 80 70 33
47
Line 10 : 41 48 72 33 47 32 37 16 94 29
43
Line 11 : 53 71 44 65 25 43 91 52 97 51 14
73
Line 12 : 70 11 33 28 77 73 17 78 39 68 17 57
91
Line 13 : 91 71 52 38 17 14 91 43 58 50 27 29 48
67
Line 14 : 63 66 04 68 89 53 67 30 73 16 69 87 40 31
98
Line 15 : 04 62 98 27 23 09 70 98 73 93 38 53 60 04 23

My answer being 1064. I know the right answer because I got frustrated and found it on google - though still cant make sense of why my program isn't giving the right answer.
Thanks for your help!

you will have to use another logic for you program. altough your logic is good at first if you lower your triangle (if you reduce the number of rows) then you 'll see that your solution isn't good
Click Here

for instance:

        5
       1 2
      9 4 5
     9 7 6 12
   11 2 33 4 5

following your code you would do this:
5+2+5+12+5=29--> final result
but have in my mind that there are other routes as well

for instance:
take the most left route and go down
--> 5+1+9+9+11=35
35>29 --> that is your solution isn't 100% correct

commented: Keep up the good work! +15

Yes! I messed up my logic there. Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.