Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2016-01-09 23:36:18

anna_gg
Member
Registered: 2012-01-10
Posts: 232

Bottle with pills

I was given an opaque bottle with 218 black and 217 white pills and I will play the following game with myself: I will draw 2 random pills and if they are both white, I keep one and put back the second in the bottle. If one is black and the other is white, I keep the white and return the black in the bottle. Finally, if both pills are black, I keep both of them and add a white pill in the bottle (from some extra stock that I keep separately). I keep playing until there is only one pill left in the bottle. What is the probability for the last pill to be white?

Offline

#2 2016-01-10 05:08:06

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,877

Re: Bottle with pills

Hi anna_gg,


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#3 2016-01-10 08:12:43

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Bottle with pills

Code please?


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#4 2016-01-10 09:27:38

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,877

Re: Bottle with pills

Hi Bobby,

I don't know if I should really hide this, but here's the code (a bit unrefined and rather LB-like, I think), + 2 more results:

Edit: Code is quite flawed and doesn't give the right answer, which is 1 (or 100%).

Last edited by phrontister (2016-01-12 02:30:41)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#5 2016-01-10 14:19:50

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Bottle with pills

Hi;

I am thinking that the probability of a white pill in this case is 1. Meaning the percentage of times it will be a final white pill is 100%.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#6 2016-01-10 14:28:50

Relentless
Member
Registered: 2015-12-15
Posts: 631

Re: Bottle with pills

Hi bobbym,

It is theoretically possible that none of the first 217 pairs are two blacks, in which case all of the whites will be gone. I think this disproves your hypothesis, although the odds are evidently stacked heavily against a final black pill.

The problem seems to be all about the frequency of all-black pairs to non-all-black pairs. There must be very few of the former for the final pill to be black.

Last edited by Relentless (2016-01-10 14:38:57)

Offline

#7 2016-01-10 14:50:24

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Bottle with pills

I do not believe you can ever be left with a single black pill.

When you start with an odd number of black pills then it is possible to be left with a single black pill. But when you start with an even number of black pills then you can never be left with 1 black pill in the bottle.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#8 2016-01-10 16:06:40

Relentless
Member
Registered: 2015-12-15
Posts: 631

Re: Bottle with pills

I see!

Offline

#9 2016-01-10 23:56:12

anna_gg
Member
Registered: 2012-01-10
Posts: 232

Re: Bottle with pills

Guys thank you very much for your replies! Only by intuition, as I am not a programmer and I cannot write code (but fortunately I can understand a simple routine) this was also my reply. I experimented with 7 pills (4 black and 3 white) and I got 100% white. I guess that as the number increases, we get closer to 100%, provided that the number of black pills at the beginning is even.
Is there any way to prove this without the use of code (i.e. with the probabilities or by eliminating the possibility of a black pill at the end)?

Offline

#10 2016-01-11 01:55:22

Relentless
Member
Registered: 2015-12-15
Posts: 631

Re: Bottle with pills

Hi anna_gg, I will try to explain what bobbym saw, and I think it will count as a proof that it is white 100%.

First note that a black and white pair and a white pair have the same outcome; one white is removed. Therefore it is only important whether a pair is only black, or not only black.

Since two blacks are removed only when a pair of black pills are drawn, all of the black pills will be gone precisely on the 218/2 = 109th black pair.
All of the whites will be gone when the sum of the black and white pairs and only white pairs is 217 greater than the number of black pairs.

Working out the probabilities of one colour running out first is an interesting problem in its own right, but the question is what colour is the single remaining pill.
Assume that all the whites do run out. Then one white will be added and two blacks subtracted because the next pair will be only blacks. Since it is always two blacks that are subtracted, for this problem the number of black pills must always be even; therefore if there is one pill remaining, it cannot be black.

Furthermore, it is certain that if the game is played long enough, there will eventually remain one white pill. This is because, no matter how many times white runs out, they will just keep replenishing from the extra stock until all the black pills are gone.

Offline

#11 2016-01-11 02:31:57

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Bottle with pills

Yep! We can not be left with a black pill when we start with an even number of black pills.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#12 2016-01-11 04:56:31

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,877

Re: Bottle with pills

bobbym wrote:

Yep! We can not be left with a black pill when we start with an even number of black pills.

True. I'd seen that with my sim, but didn't pick up on its implication. Btw, my code in post#4 is incorrect, which I've noted there.

There are three draw options:
- WW and WB, both yielding W=W-1 and B=B;
- BB, yielding both B=B-2 and W=W+1. This is the only option that affects black's total, reducing it by 2 each play.

Each play reduces the bottle's contents (originally 435) by one pill. This limits the number of valid plays to 434, leaving one pill (white) in the bottle.

The following is the only combination of plays & draws that works. It empties the bottle of all blacks, and all whites except one:
A. BB: 109 @ 2 = 218
B. Others (ie, any WW and WB): 216 @ 1 = 216
C. Last pill (white): 1
D. A+B+C = 435 (the bottle's original contents)

A & B above can be arranged in any play order that doesn't reduce the total of either colour in that play to a negative number.

Here is an example of a game with random draws as illustration:


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#13 2016-01-11 07:55:25

Relentless
Member
Registered: 2015-12-15
Posts: 631

Re: Bottle with pills

Oh yes, that is clear too isn't it... There will always be exactly 434 draws. Well I suppose that is all wrapped up!

Does anyone want to calculate the probabilities of each colour running out first? Or the case of 217 white and 217 black? Haha

Last edited by Relentless (2016-01-11 14:15:45)

Offline

#14 2016-01-11 09:55:54

anna_gg
Member
Registered: 2012-01-10
Posts: 232

Re: Bottle with pills

Excellent work from all of you!! Many thanks for elaborating!!

Offline

#15 2016-01-11 12:36:18

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Bottle with pills

Nope, there is still the other problem.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#16 2016-01-11 13:52:15

Relentless
Member
Registered: 2015-12-15
Posts: 631

Re: Bottle with pills

Hi,

Having thought about it, the case of an odd number of black pills to start with will lead to a 100% chance of the last pill being black.
Think about it - as long as more than one black is in the bottle, a white will be added sooner or later. An odd number of black pills can't all be taken out of the bottle. And inevitably, when one black remains, all the whites will then go.

The probabilities of running out first... that just might require coding ability xP

For anyone who might be interested, the problem is:
Beginning with 218 black and 217 white, what is the probability that 109 black pairs will be drawn before the sum of non-black pairs becomes 217 greater than the number of black pairs?
That will give the probability of black running out first.
It appears to me, intuitively, that the probabilities will be somewhat close to 50-50, but I am not confident of that

Last edited by Relentless (2016-01-11 14:07:25)

Offline

#17 2016-01-12 01:58:49

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,877

Re: Bottle with pills

Hi Relentless,

...what is the probability that 109 black pairs will be drawn before the sum of non-black pairs becomes 217 greater than the number of black pairs?

I probably haven't understood your intent there, but this problem seems to be different from the one you set in post #13:

Does anyone want to calculate the probabilities of each colour running out first?

Anyway, I think the answer to the earlier-set problem is that black:white = approx 0.67:0.33.

This is the result I got after running 2000 games in Excel...manually. One benefit of doing it manually is that I discovered that I can operate my Logitech Marathon M705 mouse at 400cpm, which, though not astoundingly quick, is nevertheless very pleasing. So, running the 2000 games only took about 5 minutes and enabled me to achieve a good approximate result weeks before I'd've completed coding the problem in M (ie, if I'd ever worked out how to do it).

Of course, no sooner has white run out of pills than the necessary presence of at least one pair of black pills returns white's pill count into the black at the next draw.

EDIT: Worked out how to automate running the games in Excel. Ran it for 10000 games, with the same result as for the 2000 above.

Last edited by phrontister (2016-01-12 19:02:33)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#18 2016-01-12 06:33:07

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,996
Website

Re: Bottle with pills

The configuration must pass through a three pilled stage.

Case I: It is a WWW
We choose WW. New Configuration: WW. We are forced to choose WW again. New Configuration: W

Case II: It is a BBB (We've to prove that this is non attainable)

Case III: It is a WBW (We've to prove that this is non attainable)

Case IV: It is a BWB.
Case IV a: We choose BW. New Configuration: BB. We are forced to choose BB again. New Configuration: W
Case IV b: We choose BB. New Configuration: WW. We are forced to choose WW again. New Configuration: W

Proof that Case II is unattainable: Notice that no transform alters the parity of black pills. Hence, we cannot have an odd number of pills.

Proof that Case III is unattainable: Notice that no transform alters the parity of black pills. Hence, we cannot have an odd number of pills.

Later Edit: Too much hard work for no reason. I should have noticed that we cannot have 1 black pill, or an odd number of black pills left.

Last edited by Agnishom (2016-01-12 06:35:24)


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#19 2016-01-12 08:10:33

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Bottle with pills

Hmmm, yes you should.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#20 2016-01-13 03:20:43

Relentless
Member
Registered: 2015-12-15
Posts: 631

Re: Bottle with pills

Haha smile I should have too; my excuse is that it looked so much like a coding problem that I did not bother to take a deductive approach hmm

Hi phrontister, that is interesting news, good work! My reasoning for my question giving the probability of black running out first goes like this:
If black runs out, that is because there have been enough black pairs to deplete the bottle, and each black pair removes two black pills. Therefore the number of black pairs needed is 218/2, and this is where I get 109 from.
White loses one pill for every not-only-black pair, and gains one for every black pair. This means that 217 + the number of black pairs - the sum of non-black pairs = the number of white pills left. To make that equal zero, the sum of non-black pairs must be 217 greater than the number of black pairs.

Thus the question asks in a more mathematical manner for the chance of the conditions for no black pills being met before those of no white pills

Can you provide an insight into why the black pills are twice as likely to run out first? I still cannot picture it, although I don't have the benefit of having generated games in progress.

incidentally, it is funny you mention clicking speed. I discovered several years ago that I was able to maintain 800cpm for 30secs,  and it is strange to have such a trivial talent xD I do not think there is a confirmed record above 1100cpm,  although nobody would bother about it haha

Last edited by Relentless (2016-01-13 03:52:22)

Offline

Board footer

Powered by FluxBB