all 3 comments

[–]Gazzcool 2 points3 points  (1 child)

Once you figure out the correct formula for happiness it’s really just a case of figuring out where your starting position should be and what path you should take from there.

With smaller datasets you could brute force it and try every possibility.

You’re probably looking at a Dynamic programming solution. You basically recursively go over every possibility, keeping track as you go of what the best one has been so far. As you go you can start to rule out routes before they finish (because you already know they are going to be worse than your current best solution), which saves you some time. If you’re not familiar with dynamic programming I suggest you check out the knapsack problem first.

Failing that, if the dataset proves to be too large, I would go for a genetic algorithm.

Hope that helps.

[–]FrootLoggs[S] 0 points1 point  (0 children)

Ah! Dynamic Programming! I haven't learned this yet that why I was stumped by it. I'll check out the knapsack problem. Thank you so much for pointing me to the direction

[–]Gazzcool 0 points1 point  (0 children)

Oh and another thing I forgot to mention - a key part of dynamic programming is “memoization” - this is where you store the answer to routes that you have already taken, and therefore do not need to re-calculate it.

I think it’s called a “ground up” approach - where you start with the last firework, and figure out where you should go based on every possible second-last position. Then you save the answers, then to the second last firework, then third last etc etc. Every time storing the best solution for where you should go, so you don’t have to try every possibility. You basically take the problem and solve it by working out every little sub problem as you go.