You are on page 1of 4

How Many Pennies?

A problem came up at lunch yesterday: Imagine shaking a bag of fair pennies and dumping them out on a table. How many pennies
do you need to dump out before you have a ninety percent probability of having 100 heads?
A fair penny is one that has an equal chance of coming up heads or tails, that is, a 50% probability of coming up heads.

First, it's clear you need more than 100 pennies, and it's intuitive that you need more than 200.

A collection of pennies obeys the binomial probability distribution. The following is the probability that, out of n pennies, exactly k
come up heads if every penny has a probability p of coming up heads. For a fair penny, p = 1  2.

pk H1 - pLn-k
n!
k! Hn - kL!
In[62]:= fAk_, n_, p_E :=

That formula is not difficult to understand. Imagine numbering the pennies and then writing out every possible outcome: penny 1
heads, all the rest tails; penny 2 heads, all the rest tails; pennies 1 and 2 heads, all the rest tails; and so on. It's feasible to do this by
hand for some small number of pennies.

The number of different outcomes you will write is 2n , and the number that have exactly k heads is n !  k ! Hn - kL !. The outcomes are

mutually exclusive, and each of of the outcomes has a probability pk H1 - pL


n-k
, where p is the probability of heads and 1 - p is the
probability of tails -- the formula is a little more general than we need since it accounts for unfair pennies, but the generality is
instructive.
If you'd like more explanation, here is a great web site: http://faculty.vassar.edu/lowry/webtext.html

Go further. An outcome of k heads is mutually exclusive with an outcome of k+1 heads, and so on. Therefore, the probability of at
least k heads is this:

In[63]:= fgAk_, n_, p_E := Sum@f@i, n, pD, 8i, k, n, 1<D

This is harder than average to reduce, but Mathematica has a great library of special functions and easily figures out that

In[64]:= fg@k, n, pD  FullSimplify

pk GHn + 1L H1 - pLn-k 2 F 1 J1, k - n; k + 1; N


Ž p
p-1
Out[64]=
GH-k + n + 1L

or, with the symbols resolved out

In[65]:= fg@k, n, pD  FullSimplify  OutputForm


Out[65]//OutputForm=

-k + n k
((1 - p) p Gamma[1 + n]
p
Hypergeometric2F1Regularized[1, k - n, 1 + k, ------])
----- /
-1 + p
Gamma[1 - k + n]

The regularized hypergeometric function has a simpler form


2 probs001.nb

F 
p-1
In[76]:= FunctionExpand žHypergeometric2F1RegularizedB1, k - n, 1 + k,
p
OutputForm
Out[76]//OutputForm=

-1 + p
Hypergeometric2F1[1, k - n, 1 + k, ------]
-----
p
------------------------------------------
-----------------------------------------
Gamma[1 + k]

The hypergeometric functions are a beautiful, deep, and rich topic. Wikipedia has a decent page on them: http://en.wikipedia.org/wiki-
/Hypergeometric_function. Ditto the gamma function: http://en.wikipedia.org/wiki/Hypergeometric_function.

Numerical Samples
Two Coins
Check that the probability of one head up when flipping two fair pennies is 1/2 -- there are four possible, independent, mutually
exlusive outcomes, and two of them have 1 head up

F
1
In[67]:= fB1, 2,
2
1
Out[67]=
2

Only one of the four outcomes has both heads up, and it must have probability 1/4:

F
1
In[68]:= fB2, 2,
2
1
Out[68]=
4

The probability of having at least 2 heads had best be 1/4 also:

F
1
In[69]:= fgB2, 2,
2
1
Out[69]=
4

And the probability of at least 1 head had best be 3/4:

F
1
In[70]:= fgB1, 2,
2
3
Out[70]=
4

Consider the formula "unit-checked."


probs001.nb 3

Consider the formula "unit-checked."

100 Coins
Back to the original problem:

What's the probability of at least 100 heads if we flip 150 coins?

F
1
In[71]:= NžfgB100, 150,
2
Out[71]= 0.0000272377

about 2.7 in 100,000. We'd have to throw out our bag around 35,000 times to get one outcome with at least 100 heads up.

How about if we have 250 pennies in our bag?

F
1
In[72]:= NžfgB100, 250,
2
Out[72]= 0.999393

Almost all the time. If we threw out our bag 1,000 times, only once, on average, would we expect NOT to have at least 100 pennies
heads up.
Manual binary search leads us to the final answer:

F
1
In[79]:= NžfgB100, 217,
2
Out[79]= 0.889174

F
1
In[73]:= NžfgB100, 218,
2
Out[73]= 0.900981

218 is the smallest number of pennies in the bag that give us a 90% probability of yielding 100 heads up.

We can plot the "at-least 100" function for all numbers of pennies in our bag from 150 to 250.
4 probs001.nb

F, 8c, 150, 250<F


1
In[74]:= PlotBfgB100, c,
2
1.0

0.8

0.6

Out[74]=
0.4

0.2

180 200 220 240

We could do lots more analysis, but this straightforward numerical demonstration gives us a quick answer.

You might also like