keshav.is / coding / coin toss

I read a very interesting math riddle recently, which inspired this blog post.

Let's say I give you a fair coin and offer you a bet on the outcome of its flips. If I bet on heads and you bet on tails, we have an equal chance of winning/losing. If I bet on the sequence heads-tails, and you bet on heads-heads, we both have a 1/4 chance of winning and a 3/4 chance of losing. The pattern continues from there - every combination of heads and tails is equally likely to win as any other combination of heads and tails- however, as the combinations get larger, the probability that they don't occur grows exponentially larger.

But what if I place a bet on which sequence will appear first? If I bet on head-head, and you bet on tail-head, we keep flipping the coin until either of our sequence shows up. What is the probability of either of us winning now?

If you are thinking 50-50, you are wrong. Once we enter the realm of sequences, it is no longer a series of independent events- each event affects how likely a certain outcome becomes. Let's observe heads-heads (denoted HH) versus tail-heads (denoted TH), and look at all the possible sequence of flips (permutations generated in Mathematica by executing "With[{length = 4}, Map[StringJoin, Tuples[{"H", "T"}, length]]]").

2 flips: {HH, HT, TH, TT} -> HH has 1 winning chance, TH has 1 winning chance. 3 flips: {HHH,HHT,HTH,HTT,THH,THT,TTH,TTT} -> Some of the permutations can't occur (HH will have already won), so TH has 2 winning chances, HH has none. 4 flips: {HHHH, HHHT, HHTH, HHTT, HTHH, HTHT, HTTH, HTTT, THHH, THHT, THTH, THTT, TTHH, TTHT, TTTH, TTTT} -> Excluding impossible permutations, HH has 1 winning chance, TH has 3.

As you can see, it isn't a 50-50 game- some combinations of flips are more likely to show up than others. In the case of HH vs. TH, the chances to win divided by total chances is 2/14 for HH, and 6/14 for TH. So, you are 3 times more likely to win if you pick TH than if you pick HH (75% odds are in your favor), after 4 flips of the coin. It doesn't apply to other strings of flips, because after each flip, one gets more likely than the other. We'll look at where the probabilities converge to later in this post.

But what about "HHHTHTH" vs. "HTHHTHH"?

This nifty little coin trick is something that people instinctively believe is a 50-50 chance. So if you're ever down on your luck, strike a bet for HH vs. TH on a series of coin flips- the Law of Large Numbers guarantees that you will win. This post should allow readers of this blog to exploit the general population that doesn't read this blog- but in how many ways?

What if I bet on "HHT" and the other person bet on "TTH"? Is there any quick and easy way to find out our odds? There is the intuitive method- if I bet on HHT, and you bet on HTT, and a HH shows up in the flipping, I am guaranteed to win. Think about this- if a HH has shown up, and the next flip is T, I win- if the next flip is H, neither of us can win, and I will just bide my time until the next rounds until a T finally shows up. Once it does show up, I'll already have won- there's no way a HTT can occur without a HHT occurring first. If this doesn't make sense, try drawing out the tree diagram (shown below) and check it for yourself.