Here is a game played between two parties, each taking turns. There are 21 flags. The first person, in her turn, must pick up one, two or three flags—the game shifts to the second one to do the same. The game continues. The person who picks up the last flag is the winner. In theory, the game offers an advantage to one person. Who is it, and what is her winning strategy?

As with many games, this can also be solved by thinking backwards. Imagine only one flag remaining; the person whose turn comes up wins. The same is true for two and three flags, as she can take one, two, or three in her turn. Let’s denote that person – the first in line – 1.

1 wins 1, 2, 3
There are now four flags. Person 1 can remove one, two, or three, but the last chance is for person 2.

1 lose: 4
If there are five flags, 1 can choose one flag, and 2 is left with a four-flag situation, i.e. 2 loses. The same is true for six and seven.
1 wins 1, 2, 3, 5, 6, 7
In the case of Eight Flags, if 1 takes one, two or three, 2 gets one of the winning numbers (8-1 = 7, 8-2 = 6 or 8-3 = 5).
1 lose: 4, 8
Continuing this pattern, person 1 can win when the flags in her turn are 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19, and 21 and will lose when the flags are 4, 8, 12, 16, 20.
Since 21 is on person 1’s list, she can win this game by always picking the flags, leaving a multiple of four to the opponent. So, at the beginning of the game, the starter picks up one flag, leaving the opponent to choose next. Person 2 can leave 19, 18, or 17 for person 1. Person 1 will then pick such that person 2 gets 16. The game goes on, and 1 eventually wins.
Can You Solve The 21 Flags Game From Survivor?: MindYourDecisions