Calculate the probability of a “good” dice roll

diceprobability

As part of a bigger game-theory problem, I've been trying to solve a rather simple probability question, and I seem to be getting the wrong answers. Here's the problem:

Dice are rolled to determine a pass or fail, and the probability of either is equal. If the roll is a pass, the entire condition passes, and if it is a failure it is re-rolled until either it passes, or has failed 3 times. What is the probability of the entire condition passing?

The way I solved this is by listing all possible states, of which there are four:

fail fail fail = failure
fail fail pass = success
fail pass      = success
pass           = success

based on this, the probability of overall success is $\frac{3}{4}$, or 0.75.

To test it, I wrote a simple simulation in python as follows:

def test():
    fails = 0
    while fails < 3:
        if random.choice([True, False]):
            return True
        else:
            fails += 1
    return False


passes = 0
for i in range(1000000):
    if test():
        passes += 1

print(passes / 1000000)

It shows that the probability is 0.875. I'm sure that the simulation is corrent – I rewrote it in several different ways and came up with the same answer each time. So where am I going wrong with the mathematics?

The followup is to generalise this slightly where the probability of a pass or fail roll is not equal (e.g. only a 6 of a 6-sided die means pass). I have no idea how to solve that though.

Best Answer

To see why the probability is $\frac78,$ let's slightly rephrase the question: let's say instead of simulating the flips until we get a success (let's say heads) let's just flip the coin three times straight away and then look at the results. A set of three flips is successful if and only if there is at least one heads in the three flips, so the probability of a success must be equal to the probability of getting at least one heads.

So, letting $X \sim B(3, 0.5)$ be the number of heads, we want $\text{P}(X \geq 1).$ By the law of complements, this is equal to $1 - \text{P}(X = 0) = 1 - \left(\frac12\right)^3 = \frac78.$

Alternatively, using a sample space, there are $2^3 = 8$ possible sequences of three flips, and only $1$ has all three tails, so the other $7$ have at least one heads for a probability of $\frac78.$

Related Question