Qm
BrainteasersJane StreetOptiver

Two piles, take from one or equally from both

Two piles of stones hold 3 and 5 stones. On each turn a player either removes any positive number of stones from one pile, or removes the same positive number from both piles. The player who takes the last stone (leaving both piles empty) wins.

With best play, does the first or the second player win from (3, 5)? Justify it by finding the losing positions with small piles.

Show a hint

Positions (a, b) and (b, a) are the same. Work out the losing positions in increasing order: (0, 0) is losing for the player to move. Then find the smallest positions from which every move leads to a winning position.

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

Twenty coins in a circleGuess each other's coinPlacing knights so that none attackNim where the last stone losesRacing a rook to the corner
All questions →