Project Euler Problems 1 to 100 - Problem 18: Maximum path sum I

Tell us what’s happening:
Describe your issue in detail here.
Again, the deceptive instructions. TOP TO BOTTOM and STARTING AT THE TOP are given. Then the answer is approached from bottom to top. SMFH.
Your code so far

function maximumPathSumI(triangle) {
  // Copy the triangle
  //   Note: not needed if we are ok with mutating the input
  const triangleCopy = triangle.map(row => [...row]);
  // Find max path
  for (let i = triangleCopy.length - 2; i >= 0; i--)
    for (let j = 0; j <= i; j++)
      triangleCopy[i][j] +=
        Math.max(triangleCopy[i + 1][j], triangleCopy[i + 1][j + 1])
  return triangleCopy[0][0];
}

const testTriangle = [[3, 0, 0, 0],
                      [7, 4, 0, 0],
                      [2, 4, 6, 0],
                      [8, 5, 9, 3]];

maximumPathSumI(testTriangle);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Project Euler Problems 1 to 100 - Problem 18: Maximum path sum I

Link to the challenge:

The instructions are accurate. You get to choose what process you want to use to develop a solution that will reach the answer requested.

Note, we cannot change the language of Project Euler’s problem, so you’re complaining to the wrong people.

Maybe a little foreshadowing that these problems were written deceptively with bad instructions could be added to the front of the course since these are granite.

These problems are not deceptive with bad instructions. They are difficult problems that require research and creative thinking to get optimized solutions.

You certainly could have written a top down algorithm to solve this problem.

Top to bottom and starting at the top… not deceptive when the answer can not be achieved starting at the top? Whatever.

The answer can be archived starting at the top. It’s just much slower. (If you use an exhaustive approach instead of a ‘clever’ one)

Project Euler problems have many, many different possible solutions. Reading one answer doesn’t make that the only valid problem approach.

I would love to see one that doesn’t time out.

You can do it. Give it a try and ask questions if you get stuck.

I just verified that it can be done, so long as you are careful. The bottom up approach actually has a key feature that makes it work, and that feature isn’t starting at the bottom.

Tell us what’s happening:
Problem the SECOND with the solution: It doesn’t use “proper” for loop etiquette of curly braces around the for loops… which is something no one is taught to do. If the curly braces are added, the solution doesn’t work. Etiquette says you can leave them off for single line statements, which these aren’t.

YOU HAVE TO REMEMBER, YOU ARE TEACHING, NOT SHOWING OFF. I have encountered this so much in this journey it makes me want to stop. I mean, stack overflow is nearly this every time. Teach each lesson as if it is all they know about programming and coding, not some flex that shows you a trick you learned. The solution should be replaced with the SIMPLEST solution that a beginner could understand. All solutions should be this way. But I don’t run things so we got a bunch of show offs putting people off from coding instead of actually being teachers for newbies.

Your code so far

function maximumPathSumI(triangle) {
  let triClone = triangle.map(row => [...row]);
  for (let i = triClone.length -2; i >= 0; i--)         
    for (let j = 0; j <= i; j++) 
      triClone[i][j] += Math.max(triClone[i + 1][j], triClone[i + 1][j + 1]);
      return triClone[0][0];   
}
const testTriangle = [[3, 0, 0, 0],
                      [7, 4, 0, 0],
                      [2, 4, 6, 0],
                      [8, 5, 9, 3]];

console.log(maximumPathSumI(testTriangle));


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Project Euler Problems 1 to 100 - Problem 18: Maximum path sum I

Link to the challenge:

The solution you wrote doesn’t match the solution posted.

The most recent solution was posted on June 13 and both solutions have used {}s since that day.

The previous version used different whitespace than you posted here. If you use the code as it was originally posted and add {} as the original whitespace indicates, the older version of the solution works fine. The nested loop bodies are single statements.

@Willi_B

Jeremy and the others on here are actually great teachers. I get that you’re frustrated, but there’s no need to be rude or disrespectful.

If something like this can make you this emotional, I’d hate to see how you respond to actual hardship.

Just something to think about.

1 Like

I do not need your opinions on what I posted. I have experienced this “look what I can do” approach MANY times and as a learning student it is GROWING OLD. I am glad you are doing well.

To you, they are GREAT TEACHERS. When I encounter the above issue, they are FAILING at their task. Your experience may be different.

The above issue you listed is, unfortunately, not accurate. You seem to have made a mistake copying down the answer and are unfortunately blaming us for your transcription error.

I understand you are frustrated. Learning is hard and really taxing. But please remember to be kind to community members who are donating free mentoring and tutoring to you.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.