Qm

Take one, two or four stones

Two players face a pile of 20 stones. On each turn a player removes 1, 2 or 4 stones (never 3). The player who takes the last stone wins.

Who wins with best play, the first or the second player? What is the winning first move, and what is the rule for every move after that?

Notice that the allowed moves skip the number 3, so the usual "leave a multiple of 5" pattern from the take-1-to-4 game will not be right.

Show a hint

Work backwards from small piles. A pile of 0 is a loss for the player to move. Mark each pile size as a win or a loss and look for the pattern.

Your answer

Solving needs a free account

Answers, streaks and solutions unlock when you are signed in. Reading the question and the hint stays free.

Discussion

Sign in to join the discussion · reading is open to everyone

💡 Discussion rules

  1. No full solutions here. Hints and approaches only.
  2. Complexity, edge cases and intuition are the point.
  3. Interview experiences are welcome. Respect your NDAs.

Loading discussion…

Learn the concepts

The theory behind this question.

Related questions

Nim where the last stone losesTake one, three or fourTen prisoners and hats of ten colorsTwenty coins in a circleGuess each other's coin
All questions →