All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Probability
Colored Candy Choice (Posted on 2016-05-25) Difficulty: 3 of 5
I have 6 pieces of candy: two each of 3 different colors. They taste especially good if eaten two at a time, provided the colors are different.

These candies are in an opaque bag from which I pick two at a time. If they are different colors I eat them together (yum) but if they are the same I put them back in and draw again. I will repeat this process to eat two more.

What is the probability the last two candies will be of differing colors?

Repeat with two each of 4 colors.
Repeat with two each of 5 colors.

No Solution Yet Submitted by Jer    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution No Subject | Comment 3 of 10 |
At any given point there will be an even number of singlets and a number of doublets in the bag.  Let s be the number of singlets and d be the number of doublets.

Every time you choose two candies of differing color, you can either reduce the number of singlets by 2, reduce the number of doublets by 1 (by choosing a singlet and one member of a doublet) or increase the number of singlets by 2 while decreasing the number of doublets by 2 (by choosing 1 member of each of 2 doublets).

Let's try to build a table of probabilities, p, of success (ending up with 2 singlets), starting with the fact that no matter how many singlets there are (always an even number), if there are no doublets, p=1; and if there is nothing left but one doublet, p=0:

            doublets:
singlets:      0        1         2         3        4       5       6
    0                   0
    2          1
    4          1
    6          1
    8          1
   10          1
   12          1

Let's expand the table.

If there are s singlets and d doublets, the probabilities of going to:

s-2 singlets and d doublets: (s/(s+2d) * (s-1)/(s+2d-1)) / (1 - (2d/(s+2d))*1/(s+2d-1))
s singlets and d-1 doublets: 2*(s/(s+2d) * 2d/(s+2d-1)) / (1 - (2d/(s+2d))*1/(s+2d-1))
s+2 singlets and d-2 doublets: ((2d/(s+2d)) * (2(d-1)/(s+2d-1)) / (1 - (2d/(s+2d))*1/(s+2d-1))

where the division by (1 - (2d/(s+2d))*1/(s+2d-1)) converts the overall probability into the conditional probability given that two different colors are definitely chosen.

These conditional probabilities are then used to fill in the table spot for s singlets and d doublets, by multiplying these conditional probabilities by the respective new configuration's probabilities, and adding the three products together. This should be done columnwise, so that the entry for s+2 singlets with d-2 doublets is available. With the 12 singlets, 0 doublets we started with, the successive columns will have one fewer entries capable of being calculated.

This looks like it calls for a computer program rather than going through the tedious and error-prone calculations by hand.  BTW, this is known as dynamic program, where the table is built from the bottom up so that each entry is calculated but once. The opposite would be recursive programming, where the values of later-on (usually higher) entries are found by calling on the function for other (usually lower, but in this case involving higer s values) values, and them in turn calling on other values, until a stop is reached such as zero doubles or 0 singlets.


    10     dim prob(12,6)
    11     kill "candych.txt":open "candych.txt" for output as #2
    20     
    30     for s=0 to 12 step 2
    40       prob(s,0)=1
    50     next
    60     prob(0,1)=0
    70      
    80     for d = 1 to 6
    90       for s= 0 to 12-d step 2
    91        p1=0
   100        if s>0  then
   110         :prob(s,d)=prob(s-2,d)*(s/(s+2*d) * (s-1)/(s+2*d-1)) / (1 - (2*d/(s+2*d))*1/(s+2*d-1))
   111         :p1=p1+(s/(s+2*d) * (s-1)/(s+2*d-1)) / (1 - (2*d/(s+2*d))*1/(s+2*d-1))
   115        if (1 - (2*d/(s+2*d))*1/(s+2*d-1)) > 0 then 
   120         :prob(s,d)= prob(s,d)+prob(s,d-1)*2*(s/(s+2*d) * 2*d/(s+2*d-1)) / (1 - (2*d/(s+2*d))*1/(s+2*d-1))
   121         :p1=p1+2*(s/(s+2*d) * 2*d/(s+2*d-1)) / (1 - (2*d/(s+2*d))*1/(s+2*d-1))
   130        if d>=2 and (1 - (2*d/(s+2*d))*1/(s+2*d-1)) > 0  then
   140         :prob(s,d)= prob(s,d)+prob(s+2,d-2)*(2*d/(s+2*d)) * (2*(d-1)/(s+2*d-1)) / (1 - (2*d/(s+2*d))*1/(s+2*d-1))
   141         :p1=p1+(2*d/(s+2*d)) * (2*(d-1)/(s+2*d-1)) / (1 - (2*d/(s+2*d))*1/(s+2*d-1))
   142        print p1
   150       next
   160     next
   170
   180     for s=0 to 12 step 2
   190       for d=0 to 6
   200         print using(3,7),prob(s,d);
   205         print #2, using(3,7),prob(s,d);
   210       next  
   220       print
   225       print #2,
   230     next  
   231
   232     erase prob()
   233     dim prob(12,6)
   234     for s=0 to 12 step 2
   240       prob(s,0)=1
   250     next
   260     prob(0,1)=0
   270      
   280     for d = 1 to 6
   290       for s= 0 to 12-d step 2
   291        p1=0
   300        if s>0  then
   310         :prob(s,d)=prob(s-2,d)*(s//(s+2*d) * (s-1)//(s+2*d-1)) // (1 - (2*d//(s+2*d))*1//(s+2*d-1))
   311         :p1=p1+(s//(s+2*d) * (s-1)//(s+2*d-1)) // (1 - (2*d//(s+2*d))*1//(s+2*d-1))
   315        if (1 - (2*d//(s+2*d))*1//(s+2*d-1)) > 0 then 
   320         :prob(s,d)= prob(s,d)+prob(s,d-1)*2*(s//(s+2*d) * 2*d//(s+2*d-1)) // (1 - (2*d//(s+2*d))*1//(s+2*d-1))
   321         :p1=p1+2*(s//(s+2*d) * 2*d//(s+2*d-1)) // (1 - (2*d//(s+2*d))*1//(s+2*d-1))
   330        if d>=2 and (1 - (2*d//(s+2*d))*1//(s+2*d-1)) > 0  then
   340         :prob(s,d)= prob(s,d)+prob(s+2,d-2)*(2*d//(s+2*d)) * (2*(d-1)//(s+2*d-1)) // (1 - (2*d//(s+2*d))*1//(s+2*d-1))
   341         :p1=p1+(2*d//(s+2*d)) * (2*(d-1)//(s+2*d-1)) // (1 - (2*d//(s+2*d))*1//(s+2*d-1))
   342        print p1
   350       next
   360     next
   370
   380     for s=0 to 12 step 2
   390       for d=0 to 6
   400         print prob(s,d);"  ";
   405         print #2, prob(s,d);"  ";
   410       next  
   420       print
   425       print #2,
   430     next  
   470      
   777     close #2
   
The p1 counts verify that the weights assigned for the three possible sources of each of the probabilities add up to 1. They do.

               doublets
  singlets        0          1          2          3          4           5          6
     0        1.0000000  0.0000000  1.0000000  0.8000000  0.8769231  0.8917802  0.9072638
     2        1.0000000  0.8000000  0.8769231  0.8917802  0.9072638  0.9183540  0.9270402
     4        1.0000000  0.9142857  0.9188504  0.9245634  0.9308443  0.9365120  0.9414675
     6        1.0000000  0.9523810  0.9451139  0.9449034  0.9468746  0.9494783  0.9521768
     8        1.0000000  0.9696970  0.9608358  0.9582462  0.9580923  
    10        1.0000000  0.9790210  0.9707691 
    12        1.0000000 

               doublets
  singlets      0     1           2              3                                4                                      5                                                 6
     0          1    0            1             4/5                             57/65                               10144/11375                                     5500627/6062875   
     2          1    4/5        57/65         10144/11375                    5500627/6062875                     7132435372/7766542875                         54385624175677/58665876030125   
     4          1    32/35    1087/1183      2871116/3105375            157981084171/169718059875           10700625458543232/11426042090337875           302289395380852218263/321083208780584625375   
     6          1    20/21    48077/50869    1943079856/2056379325    71769386294183/75796085540175        34113210274641100556/35928373207203852375    752482546890087526979034523/790276099985519578276720875 
     8          1    32/33    230419/239811   3096527828/3231453225   19635660282206457/20494539662581985    
    10          1    140/143  6906433/7114393
    12          1  

Answers:

2 each of 3 colors: p = 4/5  = 0.8
2 each of 4 colors: p = 57/65 ~= 0.8769231
2 each of 5 colors: p = 10144/11375 ~= 0.8917802 
2 each of 6 colors: p = 5500627/6062875 ~= 0.9072638

  Posted by Charlie on 2016-05-25 11:37:33
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information