Saturday, September 19, 2020

The Unwinnable Game

There are 30 pieces of candy on the table. You and your opponent play in turns. In a turn, the player can take at least 1 and at most 5 candies from the table. The player who takes the last candy wins, AND RECEIVES ALL THE CANDIES.

You may even start first! So then surely you can devise a winning strategy, right?

...Right?

Player's turn
Last candy wins
YOU LOST!
The opponent took the last candy.



Solution
Sorry, like the title says, you can never win. Let's explore why this is.

Consider what's needed for you to win. In your last turn, there would need to be between 1 and 5 candies left on the table so that you can grab them all and win. However, if there would be 6 left, you would lose. Because all you can do then is leave between 1 and 5 candies, which is no problem for your opponent to finish the game in the next move.

Would there have been 7 left, you could have just taken one candy. Now there would be 6 left, and as we just saw, that is a losing position. So in this (hypothetical) case your opponent would lose.

We have now learned that if you want to win this game, your goal is to make your opponent end up with 6 candies left. To do that, it will first have to be 12 though. And before that 18. Basically: any player that is stuck with multiples of 6, can never win.

And that is exactly what your opponent in this game is doing to you. There is no clever AI here. Just one simple rule: always take as much candy so to leave a multiple of 6. That's it. The winning strategy of your opponent. I start you of with 30 candies, which is a multiple of 6. Which means you lost before you even started.

Now, after the first game you can change some parameters and let the opponent begin. If your opponent is stuck in multiples of 6, surely you can win right? Nope... I cheated a little, because now the game will start of with 25 candies. And your opponent will be quick to bring it down to 24.

Lastly, you can also set it up so that the player taking the last candy or candies, loses. Now suddenly 6 candies is a winning position. Yet 1 has become a losing position. So this just results in a small change of the strategy: leave one more candy than a multiple of 6.

No comments:

Post a Comment