# Two sixes in a row

If you repeatably roll a single die, how often do you get two sixes in a row? Put another way, what is the expected number of rolls before you get two sixes in a row (If we were to repeat this exercise a massively large number of times, what is the average number of rolls it took to get to two sixes in a row?)
Next question: What is the expected number of rolls needed to get a six followed by five? Is this answer different from the question above? Is the expected number of rolls to get six-six different from getting six-five? Are you sure?
Finally, what is the expected number of rolls until you get two sixes, not necessarily in a row?

## Starting Simple

First, lets look at how long it will take to get our first six. Intuition tells us it is six rolls, and this is right. There are six, equally likely, outcomes (for a fair die), and so we’ll need to roll, on average, six times to get a six.
Let’s get a little formal (it will help us later), and derive a formula. Let’s define E to be the expected number of rolls to get the first six. There are two things that could happen when we roll the die:
• We roll a six (1/6 chance), and this takes one roll.
• We miss the six (5/6 chance), which burns a roll, and puts us back exactly where we started
In equation form we can write this as a self-referential equation. The expected number of rolls is one sixth of a chance of taking one roll, plus (or), five sixth chances of taking that roll and being back where we started.
E = 1/6(1) + 5/6(1 + E)
After a little algebra we can see that E = 6. The expected number of rolls until we get our first six is 6.

## Two sixes in a row

Now let's graduate to the second six.
We know that the expected number of rolls to get the first six is 6, from there, we can either roll another six, or, more likely, we don't roll the second six and are right back at the beginning again. In equation form:
E = 6 + 1/6(1) + 5/6(1 + E)
6E = 36 + 1 + 5 + 5E
E = 42
The expected number of rolls to get two sixes in a row is 42!
This might come as s big surprise to you. Why is it not 36? After all, if I roll two dice that chance of getting a pair of sixes is 1/36. The answer is because that, in our case, the probabilities are dependant. The probability of rolling the second six to win is dependant on the roll before being a six too.
I know it's a little hard to wrap your mind around, but if we rolled a pair of dice, the chances of getting a pair of sixes is 1/36, so it will take an expected 36 rolls of the pair for this to occur. But, if we're rolling a single die consecutively, it will take, on average 42 rolls. Think of this like a sliding window. A roll of a non-six penalizes you twice; once for the die behind, and once for the roll yet to come.

## What about 6 followed by 5?

Is this different if we're looking for a six followed by a five?
Interestingly, yes, it is. After the six is rolled, there are three things that could happen this time:
• We get the five. Bingo, we have a winner!
• We get another six. It's not what we wanted, but it's not all bad. We're treading water, and we've got another chance to try for the five on the next roll.
• We get a {1,2,3,4} and have to reset and wait for another six to start our climb.
We need two equations for this. First lets do an equation for the bullet points above. Let's assume we've rolled a six already. Let's keep E to represent the total number of expected rolls to get 6–5, but define a new variable E6 to be the Expected number of rolls if we started with a six.
E6 = 1/6(1) + 1/6(1 + E6) + 4/6(1 + E)
Next we have the formula for the expected number of rolls. There's five chances out of six that we'll not get a six, so we've burned a roll and we're back to where we start. There's also one chance in six that we roll a six, and so we inremented the roll, and add in the expected number of rolls to get the five after the six (above).
E = 5/6(1 + E) + 1/6(1 + E6)
We have two simultaneous equations, and two unknowns. Rearranging the top equation we get:
E6 = (4E + 6)/5
Substituting this into the lower equation gives:
E = (4E + 6)/5 + 6
E = 36
The expected numer of rolls to get six-five in a row is 36!
That's correct, it takes fewer rolls, on average, to roll a six followed by a five, than a six followed by another six. If you find this hard to believe, please don't play Penney's Game. If you still don't believe it, write a few lines of code using a random number generator and prove it to yourself.

This one is pretty easy.
It's just two sequential sets of rolls to get a single six. It's expected that we'll take, on average, six rolls to get the first six, then another six from that point to get the second six.
The expected numer of rolls to get to two sixes is 12.

## Bonus

We calculated above that the Expected number of rolls to get the second six is twelve. A harder question is how many rolls do we expect it will take to get a second occurrence of any number? (If we repeatedly roll a die, how many rolls until we roll a number we’ve already seen). The first roll is guaranteed to be unique …
Things escalate quickly; the more we roll, the more we either hit one of the numbers we've already seen. If we ever get to the seventh roll, from the pigeon hole principle, we are guaranteed to roll a match. I talked about this recently in the article about dealing four-of-a-kind in the dark and getting a matching pair of socks in the dark.
We can define En as being the expected number of rolls to finish after having rolled (and thus seen) n distinct numbers. So, we know E6 = 1, as it will only take one more roll to get a match (whatever it is!)
Working backwards, for E5, there's a 1/6 chance of needing another roll, and a 5/6 chance that this roll finishes the game. We already know E6 = 1.
E5 = 1/6(1 + E6) + 5/6(1)
E5 = 7/6
It's turtles all the way down from here:
E4 = 2/6(1 + E5) + 4/6(1)
E4 = 25/18
Working our way down, we get E3 = 61/36, E2 = 115/54, E1 = 899/324, leading us to our solution of E0 = 1223/324 ≈ 3.775
The expected numer of rolls to get any match ≈ 3.775