There are 3 kegs of water. The first keg has 1 liter, the second keg has 2 liters, and the third keg has 3 liters of water in it.
Each day our traveler picks one keg at random with each keg having the same chance of being picked, and drinks one liter of water from it. When he empties a keg, he throws it away. When he is left with one keg, he records the amount of water in it.
What is the expected amount of water (in liters) remaining in that last keg?
If this expected value can be expressed as b a , where a and b are coprime positive integers, enter a + b .
Note:
You may use a calculator if you want.
Bonus: Solve this problem for 5 kegs.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
It's an insane answer
its a very good answer but I wasnt able to understand your graph, can you please elaborate?
Log in to reply
Sure. Let me try to explain that by asking a counter-question.
How would you be tackling this problem for 2 kegs?
Log in to reply
@Agnishom Chattopadhyay ok, in this case there are basically just 2 ways it could start, if he happens to pick up the one with just 1 ltr then he will finish n throw it, if he picks up the second one then he drinks 1tr and conserves the bottle as it will still have 1 ltr but whats puzzleing me is that hes not going to calculate the water leftover till he reaches last bottle!
Log in to reply
@Nishant Sood – yes, and can you do a little tree diagram for this?
Log in to reply
@Agnishom Chattopadhyay – 1 -- 2 ---1, 2---1, 1 --1 ,this is the best I could do ,in replies they wont let you do anything serious!
Log in to reply
@Nishant Sood – And the corresponding tree is this, right:
That was nice. I think TT.TT
Log in to reply
Sorry, what is TTTT?
Log in to reply
It's a crying face :p T.T extended :D
Anyways, it was really intense, but really nice at the same time.
Is there a pattern to the value of f ( a , b , c ) ? If so, we could prove it by induction.
Log in to reply
I cannot think of any recursion here.
Log in to reply
In your solution, can you add in the values of f ( a , b , c ) for when these are ≤ 3 ? That might lead others who are interested to guess at a pattern.
(Oh, and I just realized I'm committing the mistake of double notation, given that a , b were used in the question. Oh well, it should be obvious what I'm saying in the comments.
With the same method as @Agnishom, but in python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Output:
1 |
|
For the bonus, we need a more optimized solution. We'll be here soon
Hmm, I was thinking if we could improve a little by caching the values?
A code snippet in Julia to calculate the probability of any final configuration recursively (unoptimised; we should add memoisation for larger problems):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
The amount of water(in liters) left in the one last keg has 3 possible values: 1, 2, and 3. Let P(n)=the probability that the amount of water in the keg is n(n=1, 2 or 3). To get the expected amount of water, we need to determine 1 * P(1) + 2 * P(2) + 3 * P(3) .
Note that if there is water in all the 3 kegs, the probability of picking any keg at random is 3 1 . Once a keg is emptied and thrown away, however, the probability of picking a keg becomes 2 1 . In my solution, there are a lot of notations such as p(1-2-2) . This represents the probability of picking keg # on day 1, 2, 3. etc. For example, p(1-2-3-2) is the probability that the traveler picks the 1st, 2nd, 3rd and 2nd keg on day 1, 2, 3 and 4 respectively.
I. P(3) --- Let's calculate P(3) first since it's the most straightforward of all. The only last keg which could have 3 liters of water left is the 3rd keg . Therefore, P(3) = p(1-2-2) + p(2-1-2) + p(2-2-1) = 3 1 * 2 1 * 2 1 + 3 1 * 3 1 * 2 1 + 3 1 * 3 1 * 2 1 = 3 6 7 .
II. P(2) --- If there are 2 liters of water left in the last keg, then it must be either the 2nd or the 3rd keg . We can break down the calculation into the following 2 scenarios:
a. 2 liters of water left and the last keg is the 2nd keg
= p(1-3-3-3) + p(3-1-3-3) + p(3-3-1-3) + p(3-3-3-1) =
3
1
*
2
1
*
2
1
*
2
1
+
3
1
*
3
1
*
2
1
*
2
1
+
3
1
*
3
1
*
3
1
*
2
1
+
3
1
*
3
1
*
3
1
*
2
1
=
2
1
6
2
3
.
b. 2 liters of water left and the last keg is the 3rd keg
= p(1-2-3-2) + p(1-3-2-2) + p(2-1-3-2) + p(2-3-1-2) + p(2-2-3-1) + p(2-3-2-1) + p(3-1-2-2) + p(3-2-1-2) + p(3-2-2-1) =
3
1
*
2
1
*
2
1
*
2
1
+
3
1
*
2
1
*
2
1
*
2
1
+
3
1
*
3
1
*
2
1
*
2
1
+
3
1
*
3
1
*
3
1
*
2
1
+
3
1
*
3
1
*
2
1
*
2
1
+
3
1
*
3
1
*
3
1
*
2
1
+
3
1
*
3
1
*
2
1
*
2
1
+
3
1
*
3
1
*
3
1
*
2
1
+
3
1
*
3
1
*
3
1
*
2
1
=
5
4
1
3
.
Now, add the two fractions in a and b, we get P(2) = 2 1 6 2 3 + 5 4 1 3 = 7 2 2 5 .
III. P(1) --- If there is only 1 liter of water left, it could be in any of the 3 kegs. If we try to dig out all the possible situations, the calculation will get convoluted. However, there is a trick! Since 1, 2 and 3 are the only possible values, then P(1) + P(2) + P(3) must be equal to one! In other words, P(1) = 1 - P(2) - P(3). Therefore, in this case, P(1) = 1 - 3 6 7 - 7 2 2 5 = 2 4 1 1 .
Now the expected amount of water = 1 * 2 4 1 1 + 2 * 7 2 2 5 + 3 * 3 6 7 = 7 2 1 2 5 . Since 125 and 72 are coprime positive integers, the final answer is: 125 + 72 = 1 9 7
The calculations are a little simpler if we only consider the expected value of water left. Let E(a,b,c) be the expected amount of water left starting with a/b/c liters in the 3 kegs. If none of a, b, c are zero, then E(a,b,c) = 1/3 E(a-1,b,c) + 1/3 E(a,b-1,c) + 1/3 E(a,b,c-1). Also, E(0,b,c) = 1/2 E(0,b-1,c) + 1/2*E(b,c-1) and E(0,0,c) = c. Keeping in mind that E(a,b,c) is independent of the order of its arguments, it takes a few minutes with pencil and paper to calculate E(1,2,3) = 125/72, giving the required answer of 197.
Problem Loading...
Note Loading...
Set Loading...
I wish I could say that I've found a great way to solve this problem, but I have not.
The way to calculate the expected value of the water in the last keg is to actually trace all possible ways to reach the last keg weighted by their probabilities and sum them up.
Also I will use a rational number library to store this value as a rational number, so as to not loose out on accuracy.
Also, I used a monte-carlo simulation to double check my answer: