# Can You Solve The 21 Flags Game From Survivor?

On August 19, 2019 by Raul Dinwiddie

Hey, this is Presh Talwalkar. On the TV show Survivor, contestants faced off in a winner take all competition to try and win one million dollars. Most of the competitions were physical, like hiking many miles or diving underwater, but one of the challenges was mathematical. It involved 21 flags. The contestants were divided into two teams that would take turns removing flags. Each team has to remove 1, 2 or 3 flags on a turn. The team that removed the final flag wins the game. Mathematically one team can always win this game. The puzzle for you is which team is it and what is that team’s winning strategy. Give this problem a try and when you’re ready keep watching the video for the solution. So what’s the winning strategy when there are 21 flags? It’s not so easy to figure out, instead we consider the game by thinking ahead and reasoning backward. We try and imagine what would happen if we’d start a turn with a specific number of flags, and we would decide whether we can win or lose the game on that turn. So let’s say there’s just one flag. If you start out with one flag, you can obviously pick up that flag and you will win the game for sure. This goes for if there are 2 flags you are gonna win the game, and if there are 3 flags you are gonna win the game. With this number of flags you can just pick them all up and you’re going to be the one that removes the last flag. But what happens if there are 4 flags? Well you can pick up 1, 2 or 3 flags on your turn. If you pick up 1 flag you leave 3 flags for the other team and the other team is gonna pick up all 3 flags, if you pick up 2 flags you’ll leave 2 flags for the other team, but they again can pick up all of those flags. If you try and pick up 3 flags you still leave 1 flag for the other team and they can pick it up and win the game. What this means is if there are 4 flags in front of you no matter what you do you are going to lose this game. You are going to leave a number of flags that your opponent can pick up on the next turn. What would happen if there are 5 flags? In this case you could pick up 1 flag and leave 4 flags for your opponent, now your opponent is necessarily going to lose, which means you are necessarily going to win. Similarly if there are 6 or 7 flags. You could pick those up and leave 4 flags for your opponent, this would mean that your opponent is going to lose. So this means 6 or 7 flags is also a winning number of flags. What would happen if there are 8 flags? On this case if you try and pick up 1, 2 or 3 flags, no matter what you do you’re going to leave a winning number of flags for your opponent. This means if there are 8 flags you are necessarily going to lose the game if your opponent plays correctly. We can now see a pattern in what we’ve developed, if the number of flags is a multiple of 4 you are going to lose the game if your opponent plays perfectly. So we can continue this list and we can have the number of flags for when you’re going to lose the game and the number of flags for when you’re going to win the game. You can notice that 21 is in the numbers of flags for which you can win the game. So if the game starts out with 21 flags, that means the first team that picks up flags can win this game for sure. By always picking up flags and leaving a multiple of 4 for the other team. So the first team that picks up should win this game. But let’s consider what actually happened on TV. We’ll compare the optimal move to what the 2 teams could have picked up. The first move the first team should have picked up 1 flag leaving 20 flags for the other team. Instead they picked up 2 flags leaving 19 flags for team B. So if team B picked understood the winning strategy, they could now pick up 3 flags which would leave 16 flags for team A. Instead team B also picked up 2 flags and left 17 flags. This gives team A an opportunity to redeem itself, they can now pick up 1 flag and be in a winning position. What they did instead is they picked up 2 flags leaving 15. So now team B if they picked up 3 flags they’re gonna be able to leave 12 for team A, and they’re gonna be able to win the game. What did team B do at this point? They made another mistake! They picked up 1 flag, leaving 14 flags for team A! Team A could pick up 2 flags and be again in a winning position, but they made another mistake! They only picked up 1 flag here and they left 13 flags. Team B finally makes a winning move here! they pick up 1 flag and they leave 12 flags. So team B is in position to win this game as long as they play correctly the rest of the way. So team A at this point has no choice, they pick up some number of flags, if team B plays properly, team B is gonna win the game. So when there’re 11 flags left team B should pick up 3 flags, to leave 8 flags for team A. But team B messes up again! Here they only pick up 2 flags which leaves 9 flags for team A. So team A could redeem itself by picking up 1 flag and leaving 8. Instead, they make a big mistake here and pick up 3 flags which leaves 6 flags for team B. Now with 6 flags remaining, team B is able to reason out the winning strategy. So they do correctly pick up 2 flags here and leave 4 flags for team A. This was actually shown on the TV show that they are discussing that they should leave 4 flags for the other team. At this point team A realizes that they can not win the game. So they gracefully pick up 3 flags which leaves 1 flag for team B to pick up. So there were many mistakes in the way the teams played. We shouldn’t judge them too harshly because they didn’t have too much to figure this out. But if you find yourself in such a situation on the game show, you should always be able to figure out the optimal move. Did you figure out this problem? Thanks for watching this video, please subscribe to my channel, I make videos on math and game theory. You can catch me on my blog “mind your decisions” which you can follow on facebook, google+ and patreon. you can catch me on social media @preshtalwalkar. and if you liked this video please check out my books, there are links in the video description.

I would say, team b wins, because it can react to the actions of team a^^

edit: well, I was wrong^^

that one minigame in Mario party 1/2/3 (I believe)

There is a nice and much more complex variant of this: If your are allowed to take up to the half of the flags, you have to leave powers of two to win the game. You can also have a variant, where the last flags loses instead of wins the game. In this case, you have to leave multiples of 4 plus 1 resp. powers of two plus one.

This is similar to the game, 21 dares. I figured this multiple of 4 rule out to win every time as long as you go second, you will always win even if the opposition knows the rule.

I'm gonna go try this on someone.

Doctor Nim!!!

This one is too easy. The best way to do this is to start from the end, when the last flag can be taken. If there are 1, 2, or 3 flags left, you pick it/them up and you win. But if there are 4 flags left, if it's your turn, every choice is a loser. Therefore, 4 is the number you want to leave your opponent for you to win on the next move. To get to 4, you have to be on 5, 6, or 7, therefore, you need to make sure your opponent is on 8. And now we have our sequence: your opponent needs to be on a multiple of 4 at the end of every turn you make. So if there are 21 flags, the the first multiple of 4 is 20, so the first player will always win the game by taking 1 flag to leave 20, then once his opponent plays, take the amount of flags you need to make 16. Continue on down until you take the last flag and win!

Reminds me of that episode of Cyber Chase

thanks for such excellent videos, Preshtal Walker

I can't believe it , and i am not joking it took me like 10 seconds to figure it out:))

loved this.. š

Survivor is thinking like: THANKS PRESH NOW WE RAN OUT OF IDEAS AND DON'T KNOW WHAT TO PLAY.

Desperate combinatorists are like: I am going to change the number 21 to a higher number, and make it seem like I've created the problem

I am like: This is useless Presh! Also it reminds me of myself, ya know, useless BUT hey still fun

A wins, first remove 1 flag and then remove 4-amount of flags, B removed last turn.

Mind your decisions.I figured it out

The general solution for this problem is pretty simple. If you can pick up between a and b items, you want to leave a multiple of (a+b) for your opponent. This is always possible on the first turn unless it starts on said multiple.

I'm not very good with definitions yet but I like this one š

Sucks to go second

I know this video is pretty "old" but you could generalize it as "Leave a multiple of (n+1) flags for your opponent, n being the max that can be picked up at once."

I remember playing a game similar to this with my brother…. I forgot what it was called

this is the game played in my school by the name 21 . i always win the game if there are only 2 but not if there are more

What happens if i pick all the fucking flags up

my first impression:

this looks like the bomb minigame in bishi bashi

Nim

before watching the solution, i'm going to guess that team A always wins, as long as they force the situation where it's team Bs turn with just 4 flags left.

hmm. it appears i was right, but in a small way. i thought it didn't matter until you got to 7

I actually knew a reverse of this from a SNES game. "Tales of Phantasia" I think it was. There was a jar with X starting stones in it, and you want to force your opponent to take the last stone. So from playing against the AI there a few times I found out that keeping the 4x+1 to your opponent is how you won.

if Team A is smart enough.. they can easily win the game, no matter how many flags B take in each turn. Here it goes

A needs to pick up 1 flag at 1st. If B picks 2 flags, A should pick 2 flags. If B picks 3 flags, A should pick 1 flag. Precisely, if B picks x flags then A should pick 4-x flags consecutively, leaving 4 flags at the end. This way it's win-win situation for Team A

This is an old game. Survivor put a spin on the version I remember. I thought the person who picked the last flag lost the game.

If seen this problem so many times. It's just like the bee hive minigame in Mario Party 2. If you are in the right position, you'll always win the final round.

A more interesting variation on this Nim-style puzzle is if the players are allowed to remove a contiguous number of flags from anywhere in the arrangement — for example, if there is a row of four flags (normally a losing position), one player can pick two flags out from the middle, leaving the two flags on the end in separate groups which cannot be picked up on the same turn (thus making it a winning position).

I came up with a different solution. As long as Team A stays on an odd numbered course, they would win. I numbered the flags because that helped. So you'd have flag 1, 2, 3, 4, etc. If Team A picked flag 1, B 2, A 3, B 4, A 5, and continue to alternate, Team A will definitely win. However, Team B will probably not pick only 1 flag each time. So the sequence might go as follows: A 1 B2&3. In this case, all Team A has to do is be sure to pick up the next odd numbered flag, which is 5, so they'd pick flags 4 and 5. Whatever Team B does, as long as Team A makes sure to pick up the next odd numbered flag, they'll definitely win.

The game is better when loser is the team who take the last flag because it's harder to win

This is my answer before watching the answer. Team A will always win. Since they have the first move they only take 1 flag. After that they have to take the number of flags that add up to 4 when adding Team B's taken flags and then team A's taken flags. Like, if Team B takes 1 flag, team A takes 3 flags. Or if team B takes 2 flags, team A takes 2 flags. This guarantees team A to win every time.

The PBS T.V show Cyberchase does this in an episode called Problem Solving in Shangri-La

A, i think they win taking out the forth flag, like

21 flags

No matter what It goes between the forth and the 19th flag, they have to start with 2.

I think

Nope

I got it right š Thanks Presh

pausedA can always win. Leave the other team with the following totals: 20, 16, 12, 8, 4, 0. You win!

The first team can always win. Take 1 flag, there are 20 left. subsequently, take 4 minus the number of flags the other team took. In the end it will leave the other team will 4 flags, which they cannot all take, but you will be able to take the remainder

This is like the game 21, but you want the last flag

Let me do this

21-1=20 A

20-3=17 B

17-3=14 A

14-2=13 B

13-3=10 A

10-3=7 B

7-3=4 A

4-3=1 B

IDK Know what I am doing anymore

so they gave them a game where A could be the winner even if they both played pefrectly

And what if we donāt have the right to pick up the same number of flags than the opposite team ?

Since only 3 maximum flags were allowed therefore leaving the number of flags in the multiple of 4 for your opponent could guarantee your win.

So if 4 maximum flags were allowed then leaving the number of flags in the multiple of 5 for the opponent will help in winning or not?

I have another strategy , find how much number of flag is removed after B's turn, and then remove 1, if 16 are removed

2, if 15

And 3, if 14

Oh I learned how to solve a similar problem form standupmaths

hey this is harsh toe walker

My teacher had our class do this once

a very easy game to win at.

Who ever tells 13 win by logic

Flag number 5, 10, 15 and 20 is your golden numbers… if team

A starts, they will win 10/10 times I think

The team who will reach 18 first will lose.

So actually you should aim for a figure divisible with n+1 amount of flags you're allowed to pick,

when that number of flags is 1-n.

– If you get to start š Or, if the game starts from such number, you can always win as the team B.

In each case you can always match the number of flags left to that series. The probability is of course

higher that the team A gets the advantage in the start, if they can figure this out.

Interesting to know if the game creators knew of this pattern. I bet they did.

But a tired and hungrycontestant has less chance to puzzle it out, than the couch potato.

If the contestant is not working with such mathematics in his job.

Lol I actually worked this one out in less than a minute, it was similar to a game we used to play in primary school and I found out a staratergry like this and from then on never lost

I have an algorithm for this problem, you start with removing 1 if they then remove 1 you remove 3 if they remove 2 you remove 2 if they remove 3 you remove one if you use this one from the start you will win because you are always leaving yourself in a winning position.

Figured it out as soon as i heard the rules

When in doubt, make a table.

Single pile nim.

So basically the goal of a team is to make the opposing team have 4 flags left, as that would be a guaranteed win. Using all types of possible choices, if you start on team a, you will have less problems, as you will have an easy win from the start, while on team b, its difficult to make decisions that will motivate the opposition to pick the number you want. Having 5, 6, or 7 flags is also an instant win if you pick the amount of flags that will end up with 4 flags. Basically if there were 5 flags, picking 1 flag would be an instant win, and so on. I imagine having 8 flags will be an instant loss as you will end up picking from the 4 flags, however 9, and 10 flags are winning as you can keep picking flags until the opponent has 8 to pick, giving you the win. I'm sure that 11 is an instant win as well, since its basically the same as 9 an 10. 12 is a loss since you cant get to 8 flags, but the opponent can. See the pattern? Multiples of 4 are the losing numbers for this puzzle, meaning that if you are on team A, you have a pretty certain 100% chance of winning if you pick 1 flag at the start. Always make the opponent pick from a multiple of four. That is the strategy.

Can somebody please tell me what season and episode of survivor this was? Please! š

1:08 jumpscare!!!!!

This is a trivialized variation on the game Nim.

Neither makes for at good game however, as there is only one winning strategy, that strategy is fairly simple and who wins is predetermined from the start.

Itās b, my friend and I solved a similar problem in forth grade because of a popular game where you would take turns saying 1,2, or 3 numbers and try to say 21

he starts getting triggered at what they did on survivor… 4:25

Heyy I used to apply the opposite strategy in a game called 21

It's the same as the game where you count to 21 and you always want to say 4,8,12,16,20. And go second.

B if you get it to where there is a multiple of 4 on their go you win by taking whatever will when you add it to their go give you 4.

Actually, you could lose with 7

I bet the hosts laughed at this

on 8 if A goes 4 then that makes A pick up 1,2, or 3, this would leave 1, 2, or 3 for us to pick up. A would win.

Pretty sure this is a mario party minigame also

at 0:35 I called

NIMI remember this riddle with pennies and the one who picks up the last one loses.

This is just nim.

For team A to win, they only have to pick so that the sum of the flags picked by B team on the previous turn and the ones team A picks is even

TL;DR People on TV are dumbasses!

Itās just reverse 21 dares

5:10 there's something wrong presh

I saw a puzzle in professor Layton which goes off the mechanics of this but is about water spouts instead

I'm trying to remember it

always leave a number of flags divisible by four to the opposing team

Is like DR. NIM

What Season of Survivor was this played?

That's just a very tricky challenge indeed.

i solve it and i don't even need 1 second. Because i played a game one day. And it's same with this. I found a win strategy, same with that.( There is only one win strategy š )

Easy one…

Have solved his other puzzle similar to that…how to reach 31 December is its name

I worked backwards and realised that the team which picks the 17th flag wins.. Working backwards the picker of 13th, 9th, 5th and 1st flag wins.. so team A should only pick one flag at the start and then be the picker of 5th, 9th, 13th and 17th flag as the last flags

Ah, yes, Survivor Thailand, a season scorned by many as bland and boring in part because of drama-free challenges as action-packed as picking up flags. I liked it though, and Brian was a good winner.

Team A removes 1 flag and keep it at a multiple of 4 for Team B. Team A wins.

Its similar for the strat for 21 dares, but try get 1 minus the strat

It's Nim. There, saved you about 7 minutes.

Dumbasses.

This is easy if you just take time to think about it

You can see that if a team ( letās say B ) has to remove flags and their are 4 remaining, team B will always lose because they can only remove 3 out of 4 total, so team A to win every time just need to make the number of flags a multiplier of 4 (4,8,12,16,20), so firstly they remove only 1 flag, team B can remove how many they want, and than we simply remove a number of flags that in the end will leave 16 flags, and if we will keep this strategy, Team B will not stand a chance.

I didnāt watch the video yet.

A is Winning,

Here is the explanation

A pull 1 flag

B can pull 2-4

A will can pull 3-5 flag so A will pull till 5th flag and force B to pull the 6th one.

B can pull 6-8 flag.

Now A will pull 9th, 13, 17 flag to force B to pull the 18 flag.

Now B can pull 18-20 flag

So

A will pull the last flag.

There is a by far easier explanation. The team that can always win is A and this is how:

A first move is to remove 1 flag and then if (i) B removes 1 A removes 3, (ii) B removes 2 A removes 2, (iii) B removes 3 A removes1. By doing that you easily check that at the end B have to play with 4 flags not being removed and then A always win.

Here a strat if your starting after team a just subtract the the number they said by 4 and youāll make 5e a team go to four and that how you win as team b iāve done this before and it amazing

Vsauce2 have almost same thing in a video āA game you can always winā

dude you've plagiated this solution from a book and didn't even credited it.

boooooooooooooooooooooooooooooo

Itās like Honeycomb Havoc from Mario Party 2 but you can choose from 1-3 items.

What if this is asked to you all of a sudden and you don't even have a paper?

They should've watched this video before competing…