I interpreted this as a question about the expectation of a discrete random variable. And I used octave to solve this weeks riddler express.
Suppose a new pill bottle has whole tablets. Each day you pull a tablet, if it's whole, divide it and return the unused half. What's the average number of days until you pull a half tablet?
The outcomes are going to be 1 whole 1 half, 2 wholes 1 half, 3 wholes 1 half. And so on and on until all whole tablets are pulled.
So call each outcome wi h: meaning pull i whole tablets then a half tablet.
For a new bottle w0 and h0 are 100 and 0 respectively.
Assume some present state of the bottle w,h. When a whole tablet is pulled, half is consumed and half is returned, so the state becomes w-1, h+1. Which means the bottle always has 100 tablets.
So odds of pulling 1 whole tablet are 100/100, for 2 whole tablets we have 99/100, and so on, note we must take the product of pulling 1 and 2 because the odds of pulling 2 are conditioned on pulling 1 first. This is the falling factorial.
Then we ask, what are the odds of pulling a half tablet after pulling i whole tablets, this is h0 + i, because pulling i whole tablets means i divided half were placed into the bottle.
We then just solve for the expected value of n.
I got 13.2099606302160.
Suppose a new pill bottle has whole tablets. Each day you pull a tablet, if it's whole, divide it and return the unused half. What's the average number of days until you pull a half tablet?
The outcomes are going to be 1 whole 1 half, 2 wholes 1 half, 3 wholes 1 half. And so on and on until all whole tablets are pulled.
So call each outcome wi h: meaning pull i whole tablets then a half tablet.
For a new bottle w0 and h0 are 100 and 0 respectively.
Assume some present state of the bottle w,h. When a whole tablet is pulled, half is consumed and half is returned, so the state becomes w-1, h+1. Which means the bottle always has 100 tablets.
So odds of pulling 1 whole tablet are 100/100, for 2 whole tablets we have 99/100, and so on, note we must take the product of pulling 1 and 2 because the odds of pulling 2 are conditioned on pulling 1 first. This is the falling factorial.
Then we ask, what are the odds of pulling a half tablet after pulling i whole tablets, this is h0 + i, because pulling i whole tablets means i divided half were placed into the bottle.
We then just solve for the expected value of n.
I got 13.2099606302160.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% initialize | |
w0=100; | |
h0=0; | |
% sum over i which is the number of whole tablets pulled before the first half | |
i=1:w0; | |
% sequence of whole tablets | |
w = w0-(i-1); | |
% number of whole + half in bottle is constant because w-1 + h+1 = w+h | |
wh = w0+h0; | |
% h is initial plus the number of whole pulled | |
h = h0 + i; | |
% h denom is the size of the bottle when half is pulled | |
hd = w0+h0; | |
% nw is probability of pulling n whole tablets in a row | |
% it is w0 falling factorial, over bottle size which was shown as constant | |
% cumprod is optimization to avoid calculating full falling factorial each term | |
nw=cumprod(w./wh); | |
% p is proability of n whole tablets then a half tablet | |
p=nw.*(h./hd); | |
% answer is expection of number of whole tablets pulled | |
% so add 1 for the day you pull the half itself | |
a=dot(i,p)+1 |
Comments
Post a Comment