Loading [MathJax]/jax/output/HTML-CSS/jax.js

Saturday, February 4, 2023

How many bottles of beer is it again?

You and your friends are singing the traditional song, “99 Bottles of Beer.” With each verse, you count down the number of bottles. The first verse contains the lyrics “99 bottles of beer,” the second verse contains the lyrics “98 bottles of beer,” and so on. The last verse contains the lyrics “1 bottle of beer.”

There’s just one problem. When completing any given verse, your group of friends has a tendency to forget which verse they’re on. When this happens, you finish the verse you are currently singing and then go back to the beginning of the song (with 99 bottles) on the next verse.

For each verse, suppose you have a 1 percent chance of forgetting which verse you are currently singing. On average, how many total verses will you sing in the song?

Extra credit: Instead of “99 Bottles of Beer,” suppose you and your friends are singing “N Bottles of Beer,” where N is some very, very large number. And suppose your collective probability of forgetting where you are in the song is 1/N for each verse. If it takes you an average of K verses to finish the song, what value does the ratio of K/N approach?

Let's define some variables. Let's say that Bn is the number of bottles of beer on the wall in the nth verse and let's say that you start with B1=N bottles of beer. Then the transition from Bn to Bn+1 is given by Bn+1={Bn1,with probability 1pN,with probability p which holds even if Bn=1. That is, the last verse is "1 bottle of beer on the wall, 1 bottle of beer, take 1 down pass it around, no bottles of beer on the wall," but somehow perhaps having ingested a few too many of the bottles of beer, your crew could still end up singing "1 bottle of beer on the wall, 1 bottle of beer, take 1 down pass it around, N bottles of beer on the wall" and you'd have to make your way all the way back down. So in this setup, we need to also state that the transition with Bn+1=0 if Bn=0, n. Finally, let's define the expected number of verses as Vn=E[min{k:Bk=0}B1=n], for any n=1,,N.

Now since there are only two possibilities at the end of each verse, we have Vn=E[min{k:Bk=0}B2=n1,B1=n]P{B2=n1B1=n}+E[min{k:Bk=0}B2=N,B1=n]P{B2=NB1=n}=(1+VN1)(1p)+(1+VN)p=(1p)Vn1+pVN+1, for all n=1,,N, with V0=0.

So in particular, we have VN=(pVN+1)+(1p)VN1. We can use this as the base case to prove that VN=(pVN+1)k1i=0(1p)i+(1p)kVNk for all k=1,,N. In particular, assume that for some k>1, then substituting in the recurrence relationship for VNk we get VN=(pVN+1)k1i=0(1p)i+(1p)k((1p)VNk1+pVN+1)=(pVN+1)ki=0(1p)i+(1p)k+1VNk1, that is, the formula is also true for k+1. So, by induction, the formula must hold for all k=1,,N, including for instance k=N, so that VN=(pVN+1)N1i=0(1p)i+(1p)NV0=(pVN+1)N1i=0(1p)i=(pVN+1)1(1p)Np.

Solving for VN we get VN=1(1p)Np(1p)N. So in particular if N=99 and p=0.01, then we get an average of 1(0.99)990.01(0.99)99170.467 verses. However, if we set p=1/N, then we get K=VN=N1(11/N)N(11/N)N, so the fraction K/N=1(11/N)N(11/N)N=(11/N)N1e1 as N.

No comments:

Post a Comment