This is a fairly well known problem but fun if you've never thought about it before:
How many times would you expect to toss a fair coin before getting three heads in a row?
This is a fairly well known problem but fun if you've never thought about it before:
How many times would you expect to toss a fair coin before getting three heads in a row?
My intuition says 24, but the correct answer is probably lower than that. 1/8 to get 3 heads the first time, so if we toss 3 coins 8 times, 8 * 1/8 = 1. Like, I know extremely well that's not how probabilities work (it will never be 1) but I'm too lazy to field a better guess right now.
It’s also fun to consider the general case: what is the expected number of throws of a fair d-sided die until you get a chosen face N times in a row.
Summing an arithmo-geometric series you can prove:
E(d, N) = d + d^2 + d^3 + ... + d^N
But if you just guess this formula from a few cases, it’s then really easy to prove by induction!
@gregeganSF @benleis I took that challenge.
Ah, I just realised you don’t even need to guess, as there’s a fairly simple way to get the result directly.
What’s the expected number of times you need to throw a fair d-sided die to get a run of N consecutive 1s?
Call this E(N).
If we define p(k) as the probability of getting a run of length N-1 after k throws, we have
Σ p(k) = 1
Σ p(k) k = E(N-1)
To get a run of length N, we must first get N-1, in k throws for some k.
If that’s followed by a throw of 1, with probability 1/d, we will have a full run in k+1 throws.
If not, we’re starting again from scratch, so we expect E(N) more throws.
So:
E(N) = Σ p(k) [(1/d)(k+1) + (1-1/d)(k+1+E(N))]
This can be rewritten as:
E(N) = (Σ p(k)) ((1-1/d) E(N) + 1) + (Σ p(k) k)
E(N) = (1-1/d) E(N) + 1 + E(N-1)
E(N) = d (E(N-1) + 1)
So:
E(N) = d + d^2 + ... + d^N
@benleis Ooh looks fun!
Let's say the expectation is `x` and look at the first 3 flips. We get:
- T _ _ 50% of the time, which we'd expect to take 1+x flips in total because the counter resets after the T,
- H T _ 25% of the time, which takes 2+x flips
- H H T 12.5% of the time, which takes 3+x flips, and
- H H H the remaining 12.5% which takes exactly 3 flips
So x = (1+x)/2 + (2+x)/4 + (3+x)/8 + 3/8,
which after some manipulation comes out to x = 14 flips
Makes kind of intuitive sense if you think of it taking an expected 8 attempts of 3 flips to hit HHH, but instead of "costing" the full 3 flips for every attempt, it only "costs" 1 flip for 4 out of the 8 attempts that start with T, 2 flips for 2 out of the 8 attempts, and 3 flips for the HHT and HHH attempts, summing up to 14 total flips