The Dice Brain Teaser: A Technical Interview Question that Can Help You Solve Problems Better

Today’s puzzle is special. I like it even more than previous brain teasers I’ve discussed, like the monk problem and the hat puzzle.

Like the others, this is a technical question sometimes asked during job interviews (hat tip: Reasonable Deviations).

But unlike the others, this problem serves as an introduction to some powerful problem solving techniques. This puzzle can be solved by four methods, each providing a different angle to the problem.

The first method is particularly important for anyone that wants to manage risk and understand randomness. It’s a simulation technique simple enough for spreadsheets but powerful enough that it’s used by virtually all technical people, including traders, financial planners, statisticians, and engineers.

The second and third methods are clever ways to look at the problem and provide insight into solving other puzzles. The fourth method uses an infinite sum, so it could be used as an example for anyone teaching math.

The Problem

You and I play a game where we take turns rolling a die. I win if I roll a 4. You win if you roll a 5.

If I go first, what’s the probability that I win?

dice_roll

Here are some clarifying notes about the game:

–If I don’t get a 4, and you don’t get a 5, we keep rolling until one of us does get a winning number.

–The order of play matters. If I roll a 4, I win and the game ends. You roll only if I fail to get a 4.

–Someone will ultimately win the game (there is no draw). This means the probability I win is the same as the probability that you lose.

Intuition

Before going into the calculations, let’s get some intuition.

Because all rolls of a die are equally likely, both players have an equal chance of rolling a winning number. So at first glance, the odds of winning should be roughly equal.

The factor that tips the odds is the playing order. That is because if the first player rolls a 4, he wins and the game ends. The second player does not have a chance to respond.

So this game is all about estimating the size of the first-mover advantage.

If this problem were given to a math class, many students would start by drawing out a tree diagram and realize it involves an infinite series. Such precision is not required.

We can get a good idea by the brute force of simulation.

Method 1: Monte Carlo Simulation

The simplest approach is to actually play some games and count how many times the first player wins. It would be cumbersome and time-consuming to actually roll the dice hundreds of times, so let’s instead do this on spreadsheet.

This simulation technique is one example of Monte Carlo simulation, which is a method of simulating random events to get a sense of the distribution of outcomes. While this dice problem can be solved by pencil and paper, many real-world problems cannot. That is why simulating can provide answers and is more powerful in many practical problems, like planning for retirement or pricing stock options.

The dice problem requires simulating two random rolls of a die and assigning an outcome to the rolls.

Here is how I set up one round in a spreadsheet:

Dice Brain Teaser Monte Carlo Dice Roll Simulation

To simulate more trials, all that’s needed is to copy the formulas and then keep track of how may times each player wins.

How many trials are needed? This is a question that doesn’t have a precise answer because many problems sent to simulation typically have an unknown variance. Since more trials usually lead to more accurate outcomes, it usually does not hurt to simulate a very large number. In one project, I ran 10 million trials of a Monte Carlo model to estimate the price of a structured finance deal.

For this problem, the only randomness comes from the rolls of a die, which are relatively stable. Accordingly, I performed a simulation with 100,000 rounds to be safe. The result was that the first player won about 54 percent of the time.

I can be pretty sure the real answer is near this estimate. If all I cared about was an answer, this number would probably be good enough for government work.

The unsatisfying part is that the estimate gives no clue as to why the answer is correct. It’s that insight that could help in solving similar problems.

This is why I present more solutions. The next three methods arrive at the same answer and they also illustrate why the solution works.

Method 2: Backwards Induction

This dice problem is mentally tricky because many rounds end without a winner. It would seem necessary to keep track of an infinite series to arrive at an answer.

But that’s not the case. The trick is seeing that each round is really an independent sub-game. The fact that the previous round ended without a winner does not affect the winner of the current round or any future round. This means we can safely ignore outcomes without winners.

The probability of winning depends only on the features of a single round.

This simplifies the problem to a more tractable one. So now, assume that one of the players did win in a round, and then calculate the relative winning percentages.

In other words, calculate the probability the first player wins given the round definitely produced a winner.

To do that, we look at the distribution of outcomes. In any given round, the first player can roll six outcomes, as can the second player. How many of those thirty-six outcomes produce a winner, and how many are from the first player?

This diagram illustrates the answer:

Dice Brain Teaser Conditional Winning Outcomes

There are exactly 11 outcomes where somebody wins, of which 6 belong to the first player. Therefore, the first player wins with a 6/11 chance, or about 54.5 percent of the time.

This is the same numerical answer as Monte Carlo, but we get an explanation why it works.

The first-mover advantage is caused by the fact the first player wins even if both were to roll winning numbers.

But there are other ways to think about the problem too. The next method is especially interesting.

Method 3: Symmetric Thinking

This method is about using a mental trick. I particularly find it satisfying, though I can honestly say I would not have come up with this on my own.

Here is the solution from a comment by Mja at Reasonable Deviations:

Let p denote the probability that “I” (the first player) win. Since all games ultimately produce a winner, the second player wins with the complementary probability 1 – p.

Let’s figure out the chance that I win. On my roll, I have a 1/6 chance of winning the game. What happens in the 5/6 of cases when I don’t win?

If I don’t win, the second player gets a chance to roll. Now, it’s the other person that gets to roll first and I have to wait.

This means if I do not win on my first roll, the game is the same but I take on the role of the player that rolls second.

Hence, if I do not win on my first roll, my winning chances become 1 – p.

Algebraically, this can be written as:

p = Pr(win 1st roll) + Pr(not win 1st roll) Pr(win | not win on 1st roll)

p = Pr(roll 4) + Pr(not roll 4)Pr(second person rolling wins)

p = 1/6 + 5/6 (1 – p)

p = 1 – 5p / 6

11p / 6 = 1

p = 6/11, or about a 54.5 percent chance

I can’t think of immediate applications besides puzzles, but the symmetry is beautiful. This is one of those solutions seeking problems.

Method 4: Infinite Series

This is the conventional solution method for math classes. It works, but I certainly find the other methods to be more interesting.

To start, we draw an infinite the game tree illustrating the outcomes for each round of the game:

Dice Brain Teaser Tree Diagram

The first player’s winning percentage is the sum of all branches that lead to a win. These are all the odd-numbered branches in this diagram.

The first branch is reached with probability 1/6, the third branch is reached with probability 1/6 times 5/6 squared, and each subsequent odd-branch has an extra factor of 5/6 squared.

The task is solving the following infinite series:

Dice Brain Teaser Infinite Series

Using the formula for geometric series, the solution is:

Dice Brain Teaser Infinite Series Sum

So we again arrive at 6/11, or about 54.5 percent.



Share this post:

| More

Previous post:

Next post:



  • Kyle Johnson

    There are days where I can’t help but think “Math is awesome.” On those days, I know, in my heart of hearts, that being a nerd is most excellent.

  • Joon

    Very interesting. I immediately thought of the infinite series.

  • http://www.mindyourdecisions.com/blog Presh Talwalkar

    Kyle Johnson: Thank you for the comment–I share the same feeling ;)

    Joon: Yes, I think all math trained people go for the infinite series. But when I see the other answers, they are a lot easier to understand. I now try and focus more on Monte Carlo and Bayesian methods (1 and 2 above) since they are easier to explain.

  • Erik

    Darn you, Presh. You make infinite series seem so conventional. Aside from that, I absolutely adore the third solution. It’s elegant, and it reminds me of the infinite fraction 1/(1+1/(1+1/(1+…))).

  • http://www.mindyourdecisions.com/blog Presh Talwalkar

    Erik: I also thought of the infinite fraction when doing this problem, though they are different beasts. But you can be sure I’m trying to work that trick into another article ;)

  • Wade from Chattanooga

    Maybe I should study it more before I ask, but how do I apply this in complex games of RISK?

    I already found the chart for as low as 1v1 die up to 3v2 dice with the win/loss percentages. But lets say I’m in future Risk and I have 2 commanders giving me 2d8 and a 1d6 as my 3rd die, and my opponent has no commanders to give him d8s but only has 2d6 or even 1d6?

    My head is kinda of swimming here. I’ll have to read all this again another day I suppose.

  • Jason

    Wade,

    For the 2d+1d6 v 2d6 I ran a Monte Carlo (only 1,000 runs, it’s late and I’m tired) which predicted:

    Opponent Loses two: 56.7%
    Each loses one army: 26.8%
    You lose: 16.5%

    I wrote an excel spreadsheet as described in the article with the following formulas:

    D8 roll = “=INT(RAND()*7)+1″
    D6 roll = “=INT(RAND()*5)+1″
    Outcome of Highest Pair = “=IF(MAX(A3:C3)>MAX(D3,E3),1,0)”
    Where a result of 1 indicates your opponent loses an army, and a result of 0 indicates you lose one army
    Outcome of Next Pair = “=IF(LARGE(A3:C3,2)>LARGE(D3:E3,2),1,0)”
    Same rule for 1 or 0…

    I did some quick math to tally up the 1,00 runs of the simulation, and those were the probabilities.

    Since the rules of risk are different, and depend on the interaction of simultaneously rolled dice, I haven’t thought of a way to use the other methods yet.

  • Jason

    I would think you could construct an algorithm based on how likely one die is to beat another…

    There’s a 5 in 12 chance that 1d6 will roll higher than another, and a 27 in 48 chance that 1d8 will roll higher than a d6…

    You can figure out how many outcomes of each pair favor the smaller defender by summing up 1+2+3…+Np where Np is the number of pips on the defender’s die.

    You can figure out how many total outcomes are possible in each pair by multiplying the number of pips on the defender’s die by the number of pips on the attacker’s die.

    From there there should be a way to multiply out the statistics, but I only had a few minutes to think about this today.

    I’m not sure what it’ll look like, but from that you should be able to generalize a formula to determine the probabilities of each outcome given the input of who has which dice.

  • Pingback: Choosing the dealer in poker – is dealing to the first ace a fair system? - Mind Your Decisions

  • Thanh

    Can you please explain some things in #2.

    “In other words, calculate the probability the first player wins given the round definitely produced a winner.” – Why is the probability of the first player not winning a factor in all this?

    What does the second person’s turn have anything to do w/ the first person’s turn (making 36 outcomes). I understand that one round means that it’s two players and there are 36 outcomes, but the first player’s roll has nothing to do w/ the the second person’s.

    Thanks.

  • http://www.mindyourdecisions.com/blog/ Presh Talwalkar

    To answer your question Thanh, I was trying to illustrate how the game is biased for the first player. We can imagine both players rolling a die independently and the edge is when both players roll their winning number, the game is awarded the the first player. It’s that small advantage that makes the bias.

  • http://www.dowknowhow.com Rob

    Not so quick guys… the questions is “what’s the probability that I win”! Keyword “probibility”. You have all done a fine job of calculating “odds”… The probability that you WIN is 1 out of 6.

    A probability is a number from 0 to 1 inclusive, usually expressed as a fraction, which is the ratio of the number of chances of a specific event to the total number of chances possible.

    For example, if I have 6 numbers in a jar, 1, 2, 3, 4, 5, and 6, then the probability of drawing the #4 is 1/6. There is 1 chance of picking 4 and 6 total chances.

    Don’t confuse probability with odds… They are different.

  • Janus

    @Rob:

    No. You have given the probability that the first player to roll wins on his first turn. However, the probability that he wins the game is 6/11 (I used the infinite series).

  • http://www.dowknowhow.com Rob

    Wrong… You have successfully calculated odds once again. Remember…”odds” are the probability of an event happening divided by the probability of it NOT happening.

    For the cases, the odds of smoking are:
    Probability of being a smoker = 0.937 = 14.9
    Probability of not being a smoker = 0.063

    For the controls, the odds of smoking are:
    Probability of being a smoker = 0.462 = 0.859
    Probability of not being a smoker = 0.538

    You are over analyzing the question.

  • http://www.dowknowhow.com/ Rob

    Re-read the actual question.

    The question reads… “If I go first, what’s the probability that I win”

    It does not say anything about multiple rolls or an ongoing game. It simply states, I go first I win, one roll. Had they wanted to know the outcome of multiple probabilities in the event the game went on… the question would state “If I go first, what are the odds that I win”. The question is constructed to confuse and has succeeded. Yes sir… trick question. Congrats for biting, nice job on the math though!

  • http://www.mindyourdecisions.com/blog/ Presh Talwalkar

    At the risk of not being clear again, let me give my take. Janus is right: the question is the probability of winning the game, which is the sum of the probability of events until a player is declared a winner. It is not simply the probability of winning on the first turn.

    And Rob, we can find the odds of the game:

    prob 1: 6/11
    prob 2: 5/11

    Odds 1 winning: 6 to 5 (favorite)
    Odds 2 winning: 5 to 6 (underdog)

    If you are still in doubt, then please read about calculating the probability of winning in the game craps. You will clearly see the probability is based on the game going until a player wins or loses, and it is not based on simply the first roll. I hope this clarifies matters.

  • http://www.dowknowhow.com/ Rob

    As long as we’re willing to take risks we’re also still willing to learn. So it is good you are willing to step forward but at the same time you are asking me to believe what someone other than myself wrote over what I wrote because it’s in a web page…? I see… Kinda weird but okay…

    I will take your advice and read the page for you if you please answer the following questions.

    #1. What is the primary difference between probability and odds? [Please also bear in mind while answering this question that the ORIGINAL question asked purely about probability and not odds.]

    #2. Since probability and odds are very closely related and since there IS a difference between the two, when exactly does Probability no longer remain Probability and actually become odds?

    Regards… and thanks for the feedback in advance. But do try to keep in mind what the question is actually asking… All your calculations are turning the question into something it’s not asking for.

  • http://www.mindyourdecisions.com/blog/ Presh Talwalkar

    Happy to discuss this definition.

    #1: Probability is the chance an event occurs. Odds are the relative likelihood an event happens. If an event occurs with probability p, then the odds it happens are p/(1-p).

    #2: A probability does not become an odds by definition.

    The craps article was to show a document from Wolfram, a highly credible source, that illustrates a probability calculation in line the wording in this article. Same info in the Wikipedia entry for odds.

    I’m curious where our understandings differ. Feel free to provide references or instances that demonstrate your use of the word odds.

  • http://www.dowknowhow.com/ Rob

    Okay… there you go again. You keep intermingling the work=d odds with the word probability and word probability with the word odds. You first need to stop yourself from ever letting the two words reside in the same sentence. Likewise, you need to keep ALL ODDS formulas out of the equation. If there was no difference between odds and probabilities then we would not have two words that mean the same thing. Any mathematician will agree and if you look for that exactly I’m sure you yourself will find the answer all over the Internet. You’ve got to STOP confusing and intermingling the two very different applications. It is exactly why its a trick question because people cannot discern the difference between the two. Companies like Microsoft and such will use the very same tactics because they would like to find intricately thinking individuals who who actually KNOW the difference between these two components. It can make or break good mathematical based software.

  • http://www.dowknowhow.com Rob

    Let me just add add this, the only relevent piece of information I see in this question is:
    “If I go first, what’s the probability that I win?”
    When I read this line it is asking me something totally contrary to then entire rest of the message which I take to be spoiler information designed to screw you up and take you off track. you need to ask yourself… What does this question ask. The answer is in that one line. And yes indeed… All the other white noise around that one single line states many many points relating to odds. But the actual answer the person asking this question is seeking, by its own definition due to the one line, not odds related.

    If they ARE looking for all the crazy mathematical formuli you all have gone literally over the top on, then they may wish to rephrase the actual question. When encountering these kinds of questions… the answers are ALWAYS Super easy. However… because we are always expecting a super nova in an interview our minds immediately go to work and attempt to resold pi while and interviewer simply sits in their chair and watches in total amazement… If he wanted odds he would have simply said, “what are your chances” the word “chances”(plural), again changes everything… Likewise if he used “what is the “chance” (singular)… this changes everything yet again. Therefore, the probability of going first and winning the game are 1/6… It is what it is, stop reading into it. You guys are funny.. but you’re great! however, I certainly wouldn’t hire you as you would literally cost the company millions in wasted over-thought ovr-worked usless effort. Read more carefully next time. And ask yourselves “What am I really being asked” ;)

    I’m now finished with this question… you all can continue to mathematically deduce if you so choose. I stand by my answer and there is nothing more really to be said about this.

  • Sauron

    Presh, I feel inclined to remind you of an important piece of advice for whenever you’re online: Don’t feed the trolls.

  • Janus

    @Rob:

    Here is the first line in the description of the problem: “You and I play a game where we take turns rolling a die. I win if I roll a 4. You win if you roll a 5.” Note, it stipulates that the players take turns. Plural “turns.” Not each take one turn. The clarifying notes make clear that this game continues until one wins. Since player 1 winning and player 2 winning are mutually exclusive events, you are essentially making the claim that the probability of player 2 winning is 5/6, since the probability of player 1 winning is 1/6.

    I’m not sure why you think that when we all answer 6/11 we are referring to odds.

    And if you still think that the probability of player 1 winning is 1/6, I will happily play this game (as player 1) over and over with you according to the rules set out in the post. I can almost guarantee that I will come out way ahead of you.

  • Pingback: Quick puzzle: how long to get to heaven? - Mind Your Decisions

  • Pingback: Puzzle: how often does it rain? - Mind Your Decisions

  • Pingback: A Day in the Life of a Game Theorist: A Tribute to One Year of Game Theory Tuesdays - Mind Your Decisions

  • Faisal

    Here is how I solved the problem:

    Probability I win in any given round – 1/6

    Probability that my opponent wins in any given round – (5/6)*(1/6) = 5/36

    Since we keep playing till we have a winner, we just need to normalize the above two probabilities.

    So the probability I win the game is –
    (1/6)/[(1/6)+(5/36)] = (6/36)/(11/36) = 6/11

    So I do get the same answer, with slightly different logic.

  • Pingback: Quora

Previous post:

Next post: