In a BBC documentary The Secret Rules of Modern Living: Algorithms, professor tells us about a game involving 13 chocolates and a chili. I understand the solution provided by the professor, however, I want to know how can I formulate it?
Basically to understand how are we solving this problem using math? Do we make an algebraic equation? Or is it a combinatorics problem? Or is it just "an algorithm"
Problem Thirteen candies and one hot pepper are placed into a jar. Two people play with the objective to avoid being stuck eating the chili pepper. Each person is allowed to take 1, 2, or 3 candies out of the jar at a time. Turns out the solution is to think mathematically, breaking down the thirteen candies into four even groups. There is a single candy leftover. To win, a person picks one candy first. They wait for their opponnent to pick 1, 2, or 3 candies. It doesn’t matter how many their opponent draws.
Solution As long as the person takes four candies minus how many their opponent took in their turns, they will win. Say the opponent picks three candies, so the person will take only one. In that round, a total of four candies are removed from the jar. This is the winning strategy. By far, this was my favorite segment of the documentary because now I know how to game the system and never have to stoop to eating a whole chili raw.
Found the summary of problem from here - http://dflee.io/the-secret-rules/
P.S. - I'm not sure whether this belongs to math stackexchange. However, I couldn't find any rule which I was voiding by posting here.
This problem belongs to a class that we might call "Nim-type" games and clearly falls under mathematics; e.g., combinatorial game theory. Read the Wikipedia link for more information, including a mathematical formulation. The underlying theory becomes much more interesting when we ask questions such as, for what sizes of the starting heap does the first player to move have a winning strategy? If the rules for the number of heaps and the type of moves are varied, under what circumstances can the first player (or second, or in general if there are any number of players) force a win?