in reply to Re: Puzzle: Given an array of integers, find the best sequence of pop / shift...
in thread Puzzle: Given an array of integers, find the best sequence of pop / shift...

Because most people are not following this discussion they may not have noticed that Darren's solution is wrong.

What he's written is to make the best choice at every turn based on the assumption that both players will thereafter play by a greedy strategy. However the greedy solution is suboptimal play, and the smart opponent will not do that.

As an example for the game 38 67 63 43 83 66, Darren's solution says that if you pop, you'll get a final score of 4, versus -26 if you shift, so you should pop. In fact by shifting you can get a score of 8, while with pop you can be forced to a score of -8.

  • Comment on Re^2: Puzzle: Given an array of integers, find the best sequence of pop / shift...