File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programming Diversions and the fly likes [easy]Colors of dice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "[easy]Colors of dice" Watch "[easy]Colors of dice" New topic
Author

[easy]Colors of dice

Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
This was asked during one test:
Two friends A and B are playing with two dices. One dice has 5 red faces and one blue.They define the game:"If same color appears on top faces of dices ,A wins else B wins."Probability of winning of each is same(1/2).
How many faces of second dice are blue/red?
[hint: requires basic probability]


MH
Roy Tock
Ranch Hand

Joined: Jul 16, 2001
Posts: 83
Interesting...the answer is 3/3. I wouldn't have expected that!
Let R be the number of red faces on the second die. The probability of rolling two reds, then, is 5R/36. The probability of rolling two blues is 1(6-R)/36. We know the sum of the two probabilites must be 1/2, so
5R/36 + (6-R)/36 = 1/2
=> 5R + (6-R) = 18
=> 4R + 6 = 18
=> 4R = 12
=> R = 3. QED
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
OK, now for more fun: same problem, but now we have two 20-sided dice. One has 7 blue sides and 13 red. How many blue and red have to be on the second die for the probability of a match to be 50%?


"I'm not back." - Bill Harding, Twister
Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
Originally posted by Roy Tock:
Interesting...the answer is 3/3. I wouldn't have expected that!
Let R be the number of red faces on the second die. The probability of rolling two reds, then, is 5R/36. The probability of rolling two blues is 1(6-R)/36. We know the sum of the two probabilites must be 1/2, so
5R/36 + (6-R)/36 = 1/2
=> 5R + (6-R) = 18
=> 4R + 6 = 18
=> 4R = 12
=> R = 3. QED

Perfect
Roy Tock
Ranch Hand

Joined: Jul 16, 2001
Posts: 83
OK, let's generalize.
Say you have two D-sided dice. On the first, S sides are red and (D-S) sides are blue. How many red sides must there be on die 2 for the win probability to be the same for both players?
Again, let R be the number of red faces on die 2. The probability of rolling two reds is S/D * R/D = RS/DD. The probability of rolling two blues is (D-S)/D * (D-R)/D = (DD-SD-RD+RS)/DD. So since the probability of a win for either is 1/2,
RS/DD + (DD-SD-RD+RS)/DD = 1/2
=> RS + DD - SD - RD + RS = DD/2
=> 2RS - RD = DD/2 - DD + SD
=> R(2S-D) = SD - DD/2
=> R(2S-D) = D(S-D/2)
=> R(2S-D) = (D/2)(2S-D)
=> R = D/2. (assuming 2S!=D)
If 2S=D, again we find R = D/2 (proof left up to the reader).
So... Regardless of how many sides are red and blue on die 1, the probability of a win for either is 1/2 if D is even and, on die 2, half the sides are red and half blue.
It makes sense; think of it this way. As long as D is even, it doesn't matter what's rolled on die 1 if die 2 is colored half and half. If die 1 is red, odds are 50/50 that die 2 will be red. If die 1 is blue, odds are 50/50 that die 2 will be blue.
So the result is independent of the number of red sides on die 1. It could be 0, D, or anywhere in between. As long as D is even, the result holds.
Further, if D is odd, there is no correct painting of die 2.
[ July 22, 2003: Message edited by: Roy Tock ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Aww, I was hoping to get to to do more detailed math on that one. Then follow up with something like a 100-sided die with 29 red and 71 blue.
Indeed, the details of the first die are irrelevant - all we really need to know is that there are only two possible outcomes for the first die, red or blue. Then we can always get a 50% chance of a match using a second die which has a 50% chance of either color. It's like if you have an exam with true/false questions - you've got a 50% chance of answering correctly if you just flip a coin.
Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
Will the result be same even if second dice is biased?I think combination of colors on second dice should be irrelevant.
Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
It's too late for me to work this out in my head, so I'll post it as a thought exercise: how does the math work if the FIRST die is 50/50? Since the answer should be that ANY combination on the second die works, I'd be interested to see what happens with the math.
Just wondering, before I wander off into snoozeland.
Joe
Bhau Mhatre
Ranch Hand

Joined: Jun 11, 2003
Posts: 199
Originally posted by Joe Pluta:
how does the math work if the FIRST die is 50/50? Since the answer should be that ANY combination on the second die works, I'd be interested to see what happens with the math.

Look at Roy's equation:

RS/DD + (DD-SD-RD+RS)/DD = 1/2
=> RS + DD - SD - RD + RS = DD/2
=> 2RS - RD = DD/2 - DD + SD
=> R(2S-D) = SD - DD/2
=> R(2S-D) = D(S-D/2)
=> R(2S-D) = (D/2)(2S-D)
=> R = D/2. (assuming 2S!=D)
If 2S=D, again we find R = D/2 (proof left up to the reader).

If 2S=D, then R need not be D/2 as he said. It can be anything and its value will be irrelavant.


-Mumbai cha Bhau
Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
Originally posted by Mumbai cha bhau:

If 2S=D, then R need not be D/2 as he said. It can be anything and its value will be irrelavant.

Here's why (paraphrasing the original calcs):
Say you have two D-sided dice. On the first, D/2 sides are red and D/2 sides are blue. How many red sides must there be on die 2 for the win probability to be the same for both players?
Let R be the number of red faces on die 2. The probability of rolling two reds is (D/2)/D * R/D = R/2D. The probability of rolling two blues is (D/2)/D * (D-R)/D = (D-R)/2D. So since the probability of a win for either is 1/2,
R/2D + (D-R)/2D = 1/2
=> R + D - R = D
=> D = D
R factors out, so all values of R are correct!
And what this says is that if either die is 50/50, then no matter the configuration of the second die (provided it has only faces of either red or blue), the chances are 50/50 of getting two of the same color.
This is certainly not intuitive at first glance, but is very cool!
Joe
Roy Tock
Ranch Hand

Joined: Jul 16, 2001
Posts: 83
Yup, it's clearly correct that if the first die is 50/50, then the second die can be painted in whatever manner we wish.
Kinda reminds me of a few types of proof I learned in grad school:
Proof by intimidation: Because I SAID SO!
Proof by embarrasment: Can't you see it's obvious that...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: [easy]Colors of dice
 
Similar Threads
Java Static Problems
Dice probability program, using nested loops.
Help with Control Structures.
Dice Question
Probability Question