Solution to the Problem:
The strategy is to make sure that the deck contains the number of cards that's a multiple of four after your turn.
The strategy will not work for decks containing cards that are a multiple of four.
Only the 13 card deck, the 39 card deck, and the 54 card deck guarantee a win for the first player.
For example, for the 13 card deck, the first player would take one card, leaving 12 cards (a multiple of four).
If the second player takes one card, then the first player takes 3 cards, leaving 8 cards.
But if the second player takes 2 cards, then the first player takes 2 cards, again leaving 8 cards.
And if the second player takes 3 cards, then the first player takes one card, leaving 8 cards.
The use the same strategy to get down to four cards and again to win.
Here is Colin Bowey's excellent solution, which is better than my explanation:
Strategy
The first player should, on their first move, leave a multiple of 4 cards in the deck.
Let N be the number of cards in the deck.
The first player takes Nmod4 cards (that is, 1, 2, or 3), so that the remaining number of cards is divisible by 4:
N−(Nmod4)
After that, the first player always takes the complement to 4.
Whatever the opponent takes (1, 2, or 3), the first player takes enough so that the two moves total 4:
- Opponent takes 1 → you take 3
- Opponent takes 2 → you take 2
- Opponent takes 3 → you take 1
Why this works
If the first player can keep handing the opponent a deck size that is a multiple of 4 at the start of each of the opponent’s turns, the opponent is forced into losing positions:
- From a multiple of 4, the opponent must leave 1–3 cards away from a multiple of 4
- The first player then always restores it back to a multiple of 4
- Eventually the opponent faces 4 cards, takes 1–3 of them, and the first player takes the remaining cards and wins.
When it cannot work
If the starting number of cards N is already a multiple of 4, the first player cannot leave a multiple of 4 on the first move.
No matter what the first player takes, the second player can then apply the same strategy and force a win.
Which decks the strategy works for
We compute Nmod4:
- 13 cards: 13mod4=1 → Strategy works for the first player
First move: take 1 (leave 12)
- 32 cards: 32mod4=0 → Strategy does not work for the first player
(Second player can force a win)
- 36 cards: 36mod4=0 → Strategy does not work for the first player
(Second player can force a win)
- 39 cards: 39mod4=3 → Strategy works for the first player
First move: take 3 (leave 36)
- 52 cards: 52mod4=0 → Strategy does not work for the first player
(Second player can force a win)
- 54 cards: 54mod4=2 → Strategy works for the first player
First move: take 2 (leave 52)