# coin probabilities

I flip a coin three times, and then another three times. If the number of heads is the same the first and second time, I win. If the number of heads is different, then I win. If I win, you pay me one dollar. If you win, I give you 3 dollars. Is this game worth playing?

So I've figured out that for this game the $E[X] = 3p - (1-p)$ but I'm having a hard time coming up with $p$.

-
So you win both times? Certainly worth playing for you ;-) –  fgp Oct 16 '12 at 13:58
You win regardless of whether the number of heads on the first, second and third tosses is the same or different as the number of tosses on the fourth, fifth, and sixth tosses. So the game is definitely worth playing for you, and not worth playing at all for me. If it is required for me as a matter of law to play, let's skip the coin tosses and I will give you a dollar. –  Dilip Sarwate Oct 16 '12 at 13:58
Can you explain that a bit more formally? I'm curious as to the actual expectation of the game. –  Emir Oct 16 '12 at 13:59
They're commenting on a typo in the text regarding who wins when. –  Arthur Oct 16 '12 at 14:03

Let's suppose player A wins if the two sets have the same number of heads and the coins are fair. The probability of this is $$\left(\frac{1}{8}\right)^2 + \left(\frac{3}{8}\right)^2+\left(\frac{3}{8}\right)^2+\left(\frac{1}{8}\right)^2 = \frac{5}{16}.$$

Suppose B wins if the two sets are different. The probability of this is $$1-\frac{5}{16}=\frac{11}{16}.$$

So if A gains 3 dollars when winning and loses 1 dollar when losing, then A's expected net gain is $$3 \times \frac{5}{16} -1 \times \frac{11}{16} = +\frac14$$ per game.

-

Well, the probabily of seeing the same number of heads twice is the probability that you get $0$ both times plus the probability that you get $1$ both times plus the probability that you get $2$ both times.

Now, to find the probability that you get $k$ heads if you flip a coin $n$ times, observe that the probability of seeing the specific sequence (head, tail, head) is $p_{head}(1-p_{head})p_{head}$ = $p_{head}^2(1-p_{head})^1$. In general, the probability of seeing a particular sequence with $k$ heads is $p_{head}^k(1-p_{head})^{n-k}$. To get the probabily of seeing $k$ heads, you thus have to multiply that with the number of sequences with $k$ heads. That is the same as the number of ways that you can pick $k$ elements from $n$, i.e. $\binom{n}{k}$ = $\frac{n!}{k!(n-k)!}$. You thus get that the probability of seeing $k$ heads if you flip a coin $n$ times is $$\binom{n}{k}p_{head}^k(1-p_{head})^{n-k}$$

For the special case of a fair coin, i.e. $p_{head}=0.5$, you get $$\binom{n}{k}\frac{1}{2^n}$$

Now, summing up the square of those probability for all possible numbers of heads gives you the probability that the same number of heads turns up twice in a row, i.e. you get $$\sum_{k=0}^{n} \left(\binom{n}{k}\frac{1}{2^n}\right)^2 = \frac{1}{2^{2n}} \sum_{k=0}^{n} \binom{n}{k}^2$$

Thus, for $n=3$ you get the probability $$\frac{1^2 + 3^2 + 3^2 + 1^2}{2^6} = \frac{20}{64} = \frac{5}{16}$$ of seeing the same number of heads twice in two rows of 3 coin flips

-
you sure that's right? P<=1 should hold –  Emir Oct 16 '12 at 14:49
@Emir Duh, 'course not, I dropped the $^2$ of the denominator by accident. Fixed. –  fgp Oct 16 '12 at 14:54
@Emir And was apparently also unable to correctly compute $1^2+3^2+3^2+1^2$ - how I got $11$ there is beyond me. Fixed also. –  fgp Oct 16 '12 at 14:57