This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# [easy]Colors of dice

Arjun Shastry
Ranch Hand
Posts: 1906
1
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]

Roy Tock
Ranch Hand
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
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%?

Arjun Shastry
Ranch Hand
Posts: 1906
1
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
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
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
Posts: 1906
1
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
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
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.

Joe Pluta
Ranch Hand
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
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.