All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Probability
Two Pill Bottles (Posted on 2020-08-19) Difficulty: 3 of 5
Joe has two bottles of seasick pills, each stocked with 40 pills, which he takes with him on his ocean voyage.

During the trip, each time he takes a pill he chooses one of the two bottles at random with equal probability. Eventually one will run out and he's left with the other. When whichever is the first to run out does so, what's the expected value of the number of pills left in the other bottle?

  Submitted by Charlie    
No Rating
Solution: (Hide)
The expected number is 7.114230.... The probability distribution is

 1  0.0900535
 2  0.0900535
 3  0.0888840
 4  0.0865450
 5  0.0830832
 6  0.0785922
 7  0.0732092
 8  0.0671084
 9  0.0604921
10  0.0535787
11  0.0465902
12  0.0397387
13  0.0332144
14  0.0271754
15  0.0217403
16  0.0169846
17  0.0129407
18  0.0096012
19  0.0069254
20  0.0048478
21  0.0032866
22  0.0021533
23  0.0013600
24  0.0008257
25  0.0004804
26  0.0002669
27  0.0001410
28  0.0000705
29  0.0000332
30  0.0000146
31  0.0000060
32  0.0000022
33  0.0000008
34  0.0000002
35  0.0000001
36  0.0000000
37  0.0000000
38  0.0000000
39  0.0000000
40  0.0000000

The problem was presented by Paul J. Nahin in his book, Digital Dice, 2008, Princeton University Press, as a puzzle about a pipe smoker with two books of matches with 40 matches in each book.

I highly recommend the book to anyone interested in probability puzzles, as well as his Duelling Idiots and Other Probability Puzzlers.

My figures were calculated by:

DefDbl A-Z
Dim crlf$, pState(80, 40, 40), remain(40)
 

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
   pState(0, 40, 40) = 1
   For t = 0 To 79
     For a = 0 To 40
       For b = 0 To 40
         p = pState(t, a, b)
         If p > 0 Then
           If a > 0 And b > 0 Then
              pState(t + 1, a - 1, b) = pState(t + 1, a - 1, b) + p / 2
              pState(t + 1, a, b - 1) = pState(t + 1, a, b - 1) + p / 2
              If b - 1 = 0 Then remain(a) = remain(a) + p / 2
              If a - 1 = 0 Then remain(b) = remain(b) + p / 2
           ElseIf a > 0 Then
              pState(t + 1, a - 1, b) = pState(t + 1, a - 1, b) + p
           ElseIf b > 0 Then
              pState(t + 1, a, b - 1) = pState(t + 1, a, b - 1) + p
           End If
         End If
       Next
     Next
   Next
  For i = 0 To 40
    Text1.Text = Text1.Text & mform(i, "#0") & mform(remain(i), "  0.0000000") & crlf
    tot = tot + remain(i)
    expVal = expVal + i * remain(i)
  Next
  Text1.Text = Text1.Text & crlf & tot & "   " & expVal & crlf
  
End Sub

Function mform$(x, t$)
  a$ = Format$(x, t$)
  If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
  mform$ = a$
End Function
				

Comments: ( You must be logged in to post comments.)
  Subject Author Date
re: Solution Google Sheets - simulation confirmsLarry2021-03-01 19:30:18
thanksangela byner2020-09-03 04:15:14
Some ThoughtsAn observationbroll2020-08-19 23:14:29
Solution Google SheetsJer2020-08-19 14:22:11
re: Solution - ExcelJer2020-08-19 13:53:07
Solution - ExcelKenny M2020-08-19 12:37:17
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (23)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information