Serving the Quantitative Finance Community

 
User avatar
tarunvirsingh
Posts: 0
Joined: July 19th, 2008, 3:36 am

Jelly beans

May 14th, 2009, 11:02 am

We can probably reformulate the problem as follows: Starting from the point (m,n) on the x-y plane having integral grid, we move either south or west until we reach either x=-1 line or y=-1 line. Find the average value of the x or y intercept when one of the above lines is reached.Solution: Sum[i*P{(i,-1) is reached]_{from i=1 or 0 to m}+Sum[j*P{(-1,j) is reached]_{from j=1 or 0 to n}=
 
User avatar
MCarreira
Posts: 64
Joined: January 1st, 1970, 12:00 am

Jelly beans

May 14th, 2009, 11:44 am

QuoteOriginally posted by: everforgetMCarrira, your solution should be right if you not times 1/2 directly but considering the special case which both reach empty state.Yes, I see your point now. As Traden4Alpha said:QuoteThis adds one more iteration to the Pascal triangle
 
User avatar
MCarreira
Posts: 64
Joined: January 1st, 1970, 12:00 am

Jelly beans

May 14th, 2009, 12:32 pm

QuoteOriginally posted by: everforgetWhy can't both reach 0? Did you read the puzzle carefully? A simple MC will prove the number should be around 1.4, not 35 / 16, which hugely underestimate the prob for 0 jb left and in turn increased the expectation.ff[n_] := Sum[((Binomial[n + k, k] + Binomial[n + k, n])/2^(n + k) (1/2)) (n - k), {k, 0, n}];ff[4]=187/128=1.4609375N[ff[100]]=10.326
 
User avatar
quantyst
Posts: 0
Joined: June 4th, 2008, 5:08 am

Jelly beans

May 14th, 2009, 6:38 pm

QuoteOriginally posted by: quantystQuoteOriginally posted by: Junior08Got this at a junior analyst position at a fund.You have a bag of jelly beans in both of your pockets. Each bag contains 4 jelly beans. You eat one jelly bean at a time, each time reaching into a random bag... eventually, you reach into a bag and it's empty. What is the expected number of jelly beans remaining in the other bag. Part two... what is each bag contains 100 beans?Solution:Let's generalize the problem.Assume that in the beginning the left pocket has m beans, and the right pocket has n beans. And let E(m,n) denote the expected number of beans in the non-empty pocket when one of the pockets becomes empty.Clearly E(m,n)=E(n,m), E(m,0)=m, and E(0,n)=n.On the first pick of a bean, either the left pocket is decreased by one bean with probability 1/2 or the right pocket is decreased by one bean with probability 1/2. ThusE(m,n)=(1/2)E(m-1,n)+(1/2)E(m,n-1).All we need to do now is to solve the above recursion.Or, we can iterate it until we get the required result.QuoteOriginally posted by: everforgetAgain, the method is good but you misunderstood the puzzle. E( 0, n ) is not n.O.K. I need to get the initial values correct.Suppose we start with 0 beans in the left pocket and n beans in the right pocket. Upon first choice of a pocket, either the hand goes to the left pocket with a probability of 1/2, in which case the process stops and there will be n beans in the other pocket, or the hand goes to the right pocket with probability of 1/2, in which case the process will continue with 0 beans in the left pocket and (n-1) beans in the right pocket. So, we have:E(0,n)=(n/2)+(E(0,n-1)/2), with E(0,0)=0.Solving the above, we get:E(0,n)=(n-1)+(1/(2^n)).Done ... (except for a closed form of the main recursion).
Last edited by quantyst on May 14th, 2009, 10:00 pm, edited 1 time in total.
 
User avatar
FalsePositive
Posts: 4
Joined: March 10th, 2009, 1:12 am

Jelly beans

May 18th, 2009, 12:12 am

QuoteOriginally posted by: Junior08QuoteOriginally posted by: tarunvirsinghI think that we need to replace n by (n+1) in our calculations. This is because we do not have to find “the expected number of JB left when one bag gets empty”, rather, we have to find the “ expected number of JB left when we reach again into an empty bag” (in other words, we have to find the number of JB left when one bag has got (-1) beans left in it.)Yeah, it's reaching into an empty bag. So for the first part of the problem, RRRRR is a possible sequence, leaving 4 beans in the other bag. RRRRLLLLL is also a possible sequence, leaving 0 beans.Yes, you're right! So in this case I modify my formula to include all such possibilities:For n=4 I get (4 * 1 / 16) + (3 * 5 / 32) + (2 * 15 / 64) + (1 * 35 / 128) = 1.4609375which seems to be in agreement with MCarreira's result..
 
User avatar
wileysw
Posts: 7
Joined: December 9th, 2006, 6:13 pm

Jelly beans

May 18th, 2009, 12:25 pm

this is more of a mathematical curiosity:as already pointed out several times in the thread, with each bag containing n beans, the answer isthe sum above is actually equal to
Last edited by wileysw on November 11th, 2009, 11:00 pm, edited 1 time in total.