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

Home > Probability
My uncle's habits (Posted on 2013-06-28) Difficulty: 4 of 5
My uncle’s ritual for dressing each morning except Sunday includes a trip to the sock drawer, where he:
(1) picks out three socks at random, then
(2) wears any matching pair and returns the odd sock to the drawer or
(3) returns the three socks to the drawer if he has no matching pair and repeats steps (1) and (3) until he completes step (2).

The drawer starts with 16 socks each Monday morning (eight blue, six black, two brown) and ends up with four socks each Saturday evening.

(a) On which day of the week does he average the longest time to dress?
(b) On which day of the week is he least likely to get a pair from the first three socks chosen?

Source: manchi tutorials

No Solution Yet Submitted by Ady TZIDON    
Rating: 4.6667 (3 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer-assisted solution | Comment 2 of 4 |

    5   kill "unclhabt.txt":open "unclhabt.txt" for output as #2
   10     dim ExVal(6),ExProb(6)
   20     gosub *AddLevel(1,1,8,6,2)
   30     for I=1 to 6
   35       print ExVal(I)
   40     next:print
   45     for I=1 to 6
   50       print ExVal(I)/1
   55     next
   60     print
  130     for I=1 to 6
  135       print ExProb(I)
  140     next:print
  145     for I=1 to 6
  150       print ExProb(I)/1
  155     next
  160     print
  165   close #2
  170     end
  180 
  410     *AddLevel(Day,Probi,Blue,Black,Brown)
  413        local Socks,Sock3,P2blue,P2black,P2brown,P3diff
  420        Socks=Blue+Black+Brown:Sock3=Socks*(Socks-1)*(Socks-2)
  430        if Blue>=3 then
  440         :P3blue=Blue*(Blue-1)*(Blue-2)//Sock3
  450        :else
  460         :P3blue=0
  470        if Black>=3 then
  480         :P3black=Black*(Black-1)*(Black-2)//Sock3
  490        :else
  500         :P3black=0
  510        if Brown>=3 then
  520         :P3brown=Brown*(Brown-1)*(Brown-2)//Sock3
  530        :else
  540         :P3brown=0
  550        if Blue>=2 and Brown>=1 then
  560         :P2blue1brown=3*Blue*(Blue-1)*Brown//Sock3
  570        :else
  580         :P2blue1brown=0
  590        if Blue>=2 and Black>=1 then
  600         :P2blue1black=3*Blue*(Blue-1)*Black//Sock3
  610        :else
  620         :P2blue1black=0
  630        if Black>=2 and Blue>=1 then
  640         :P2black1blue=3*Black*(Black-1)*Blue//Sock3
  650        :else
  660         :P2black1blue=0
  670        if Black>=2 and Brown>=1 then
  680         :P2black1brown=3*Black*(Black-1)*Brown//Sock3
  690        :else
  700         :P2black1brown=0
  710        if Brown>=2 and Blue>=1 then
  720         :P2brown1blue=3*Brown*(Brown-1)*Blue//Sock3
  730        :else
  740         :P2brown1blue=0
  750        if Brown>=2 and Black>=1 then
  760         :P2brown1black=3*Brown*(Brown-1)*Black//Sock3
  770        :else
  780         :P2brown1black=0
  790        P3diff=1-P3blue-P3black-P3brown-P2blue1black-P2blue1brown
  800        P3diff=P3diff-P2black1brown-P2black1blue-P2brown1blue-P2brown1black
  810        ExVal(Day)=ExVal(Day)+Probi//(1-P3diff)
  815        ExProb(Day)=ExProb(Day)+Probi*(1-P3diff)
  816        if Probi<>0 then print #2,Day,using(2,5),Probi/1,using(3,0),Blue,Black,Brown,using(3,5),P3diff/1,(1-P3diff)/1,1/(1-P3diff),Probi/(1-P3diff),Probi*(1-P3diff)/1
  820        P2blue=(P3blue+P2blue1brown+P2blue1black)//(1-P3diff)
  830        P2black=(P3black+P2black1brown+P2black1blue)//(1-P3diff)
  840        P2brown=(P3brown+P2brown1blue+P2brown1black)//(1-P3diff)
  850    
  860        if Day<6 then
  870         :gosub *AddLevel(Day+1,Probi*P2blue,Blue-2,Black,Brown)
  880         :gosub *AddLevel(Day+1,Probi*P2black,Blue,Black-2,Brown)
  890         :gosub *AddLevel(Day+1,Probi*P2brown,Blue,Black,Brown-2)
  900 
  910     return


finds the expected number of tries in order to get a pair of matching socks:

day     expected number of tries
 1       35/29
 2       38962/31755
 3       80293631/64176855
 4       164300677/128353710
 5       5853613/4477455
 6       18248918/13432365
 1       1.2068965517241379309
 2       1.2269563848212879861
 3       1.2511306607343099003
 4       1.2800617683742838442
 5       1.3073527260463812589
 6       1.3585781803874448021

 
and the probability of finding a matching pair on the first try:
 
day      probability of success on first try
 1       29/35
 2       2154/2639
 3       56077/69861
 4       759690163/962652825
 5       698897/895491
 6       17570722/22387275
 
 1       0.8285714285714285714
 2       0.816218264494126563
 3       0.8026939207855598975
 4       0.7891631783244390312
 5       0.7804623385382991007
 6       0.7848530917675331186
      


 
so Saturday has the longest expected number of tries needed, and presumably the longest time to dress.  Friday is the day with the lowest expectation of success on the first try. This is paradoxical, but is related to the fact that the average of a set of numbers is not equal to the reciprocal of the average of their reciprocals; in other words the arithmetic mean is not the same as the harmonic mean.

Below is a breakdown of the days' probabilities, sorted from the output file. There are a few things to notice. For example, the .56288 probability that, on the third day there will initially be 6 blue, 4 black and 2 brown socks in the drawer, is broken down into two parts, with probabilities 0.27356 and 0.28932. That's because there are two ways of arriving at that state: the first day 2 blue socks were used and the second day 2 black, or the other way around. Needless to say, once this state is achieved, the probabilities are the same, but the contributions to the overall expected value are proportional to the probabilities of arriving at the given state.


day    prob    blue  brwn      that day's    conditional  overall     overall
        of        blk      P(fail)   P(succ)  contrib to  contrib to  contrib to
     reaching                                 exp value   exp value   prob of finding
  
 1   1.00000   8   6   2   0.17143   0.82857   1.20690    1.20690     0.82857
 
 2   0.60345   6   6   2   0.19780   0.80220   1.24658    0.75224     0.48408
 2   0.36638   8   4   2   0.17582   0.82418   1.21333    0.44454     0.30196
 2   0.03017   8   6   0   0.00000   1.00000   1.00000    0.03017     0.03017
 
 3   0.28932   4   6   2   0.21818   0.78182   1.27907    0.37007     0.22620
 3   0.27356   6   4   2   0.21818   0.78182   1.27907    0.34991     0.21388
 3   0.28932   6   4   2   0.21818   0.78182   1.27907    0.37007     0.22620
 3   0.01857   6   6   0   0.00000   1.00000   1.00000    0.01857     0.01857
 3   0.02480   6   6   0   0.00000   1.00000   1.00000    0.02480     0.02480
 3   0.07816   8   2   2   0.14545   0.85455   1.17021    0.09146     0.06679
 3   0.01466   8   4   0   0.00000   1.00000   1.00000    0.01466     0.01466
 3   0.01160   8   4   0   0.00000   1.00000   1.00000    0.01160     0.01160
 
 4   0.08747   2   6   2   0.20000   0.80000   1.25000    0.10934     0.06998
 4   0.18503   4   4   2   0.26667   0.73333   1.36364    0.25232     0.13569
 4   0.17495   4   4   2   0.26667   0.73333   1.36364    0.23857     0.12830
 4   0.18503   4   4   2   0.26667   0.73333   1.36364    0.25232     0.13569
 4   0.01240   4   6   0   0.00000   1.00000   1.00000    0.01240     0.01240
 4   0.01682   4   6   0   0.00000   1.00000   1.00000    0.01682     0.01682
 4   0.00928   4   6   0   0.00000   1.00000   1.00000    0.00928     0.00928
 4   0.08747   6   2   2   0.20000   0.80000   1.25000    0.10934     0.06998
 4   0.08271   6   2   2   0.20000   0.80000   1.25000    0.10338     0.06616
 4   0.06985   6   2   2   0.20000   0.80000   1.25000    0.08731     0.05588
 4   0.01682   6   4   0   0.00000   1.00000   1.00000    0.01682     0.01682
 4   0.00886   6   4   0   0.00000   1.00000   1.00000    0.00886     0.00886
 4   0.00928   6   4   0   0.00000   1.00000   1.00000    0.00928     0.00928
 4   0.01240   6   4   0   0.00000   1.00000   1.00000    0.01240     0.01240
 4   0.01590   6   4   0   0.00000   1.00000   1.00000    0.01590     0.01590
 4   0.01119   6   4   0   0.00000   1.00000   1.00000    0.01119     0.01119
 4   0.00416   8   0   2   0.00000   1.00000   1.00000    0.00416     0.00416
 4   0.00274   8   2   0   0.00000   1.00000   1.00000    0.00274     0.00274
 4   0.00416   8   2   0   0.00000   1.00000   1.00000    0.00416     0.00416
 4   0.00346   8   2   0   0.00000   1.00000   1.00000    0.00346     0.00346
 
 5   0.00729   0   6   2   0.00000   1.00000   1.00000    0.00729     0.00729
 5   0.07289   2   4   2   0.28571   0.71429   1.40000    0.10205     0.05207
 5   0.08411   2   4   2   0.28571   0.71429   1.40000    0.11775     0.06008
 5   0.08411   2   4   2   0.28571   0.71429   1.40000    0.11775     0.06008
 5   0.07952   2   4   2   0.28571   0.71429   1.40000    0.11133     0.05680
 5   0.00729   2   6   0   0.00000   1.00000   1.00000    0.00729     0.00729
 5   0.00413   2   6   0   0.00000   1.00000   1.00000    0.00413     0.00413
 5   0.00561   2   6   0   0.00000   1.00000   1.00000    0.00561     0.00561
 5   0.00309   2   6   0   0.00000   1.00000   1.00000    0.00309     0.00309
 5   0.08411   4   2   2   0.28571   0.71429   1.40000    0.11775     0.06008
 5   0.07952   4   2   2   0.28571   0.71429   1.40000    0.11133     0.05680
 5   0.06892   4   2   2   0.28571   0.71429   1.40000    0.09649     0.04923
 5   0.05820   4   2   2   0.28571   0.71429   1.40000    0.08149     0.04157
 5   0.08411   4   2   2   0.28571   0.71429   1.40000    0.11775     0.06008
 5   0.07289   4   2   2   0.28571   0.71429   1.40000    0.10205     0.05207
 5   0.01590   4   4   0   0.00000   1.00000   1.00000    0.01590     0.01590
 5   0.00827   4   4   0   0.00000   1.00000   1.00000    0.00827     0.00827
 5   0.00619   4   4   0   0.00000   1.00000   1.00000    0.00619     0.00619
 5   0.00591   4   4   0   0.00000   1.00000   1.00000    0.00591     0.00591
 5   0.00827   4   4   0   0.00000   1.00000   1.00000    0.00827     0.00827
 5   0.01682   4   4   0   0.00000   1.00000   1.00000    0.01682     0.01682
 5   0.01060   4   4   0   0.00000   1.00000   1.00000    0.01060     0.01060
 5   0.00746   4   4   0   0.00000   1.00000   1.00000    0.00746     0.00746
 5   0.00619   4   4   0   0.00000   1.00000   1.00000    0.00619     0.00619
 5   0.01121   4   4   0   0.00000   1.00000   1.00000    0.01121     0.01121
 5   0.01682   4   4   0   0.00000   1.00000   1.00000    0.01682     0.01682
 5   0.01121   4   4   0   0.00000   1.00000   1.00000    0.01121     0.01121
 5   0.00582   6   0   2   0.00000   1.00000   1.00000    0.00582     0.00582
 5   0.00689   6   0   2   0.00000   1.00000   1.00000    0.00689     0.00689
 5   0.00729   6   0   2   0.00000   1.00000   1.00000    0.00729     0.00729
 5   0.00388   6   0   2   0.00000   1.00000   1.00000    0.00388     0.00388
 5   0.00256   6   2   0   0.00000   1.00000   1.00000    0.00256     0.00256
 5   0.00413   6   2   0   0.00000   1.00000   1.00000    0.00413     0.00413
 5   0.00373   6   2   0   0.00000   1.00000   1.00000    0.00373     0.00373
 5   0.00530   6   2   0   0.00000   1.00000   1.00000    0.00530     0.00530
 5   0.00323   6   2   0   0.00000   1.00000   1.00000    0.00323     0.00323
 5   0.00295   6   2   0   0.00000   1.00000   1.00000    0.00295     0.00295
 5   0.00729   6   2   0   0.00000   1.00000   1.00000    0.00729     0.00729
 5   0.00689   6   2   0   0.00000   1.00000   1.00000    0.00689     0.00689
 5   0.00309   6   2   0   0.00000   1.00000   1.00000    0.00309     0.00309
 5   0.00388   6   2   0   0.00000   1.00000   1.00000    0.00388     0.00388
 5   0.00582   6   2   0   0.00000   1.00000   1.00000    0.00582     0.00582
 5   0.00561   6   2   0   0.00000   1.00000   1.00000    0.00561     0.00561
 5   0.00018   8   0   0   0.00000   1.00000   1.00000    0.00018     0.00018
 5   0.00023   8   0   0   0.00000   1.00000   1.00000    0.00023     0.00023
 5   0.00028   8   0   0   0.00000   1.00000   1.00000    0.00028     0.00028
 5   0.00028   8   0   0   0.00000   1.00000   1.00000    0.00028     0.00028
 
 6   0.01262   0   4   2   0.00000   1.00000   1.00000    0.01262     0.01262
 6   0.01262   0   4   2   0.00000   1.00000   1.00000    0.01262     0.01262
 6   0.01093   0   4   2   0.00000   1.00000   1.00000    0.01093     0.01093
 6   0.00651   0   4   2   0.00000   1.00000   1.00000    0.00651     0.00651
 6   0.01193   0   4   2   0.00000   1.00000   1.00000    0.01193     0.01193
 6   0.00044   0   6   0   0.00000   1.00000   1.00000    0.00044     0.00044
 6   0.00078   0   6   0   0.00000   1.00000   1.00000    0.00078     0.00078
 6   0.00078   0   6   0   0.00000   1.00000   1.00000    0.00078     0.00078
 6   0.00033   0   6   0   0.00000   1.00000   1.00000    0.00033     0.00033
 6   0.00060   0   6   0   0.00000   1.00000   1.00000    0.00060     0.00060
 6   0.05887   2   2   2   0.40000   0.60000   1.66667    0.09812     0.03532
 6   0.05102   2   2   2   0.40000   0.60000   1.66667    0.08504     0.03061
 6   0.05887   2   2   2   0.40000   0.60000   1.66667    0.09812     0.03532
 6   0.05887   2   2   2   0.40000   0.60000   1.66667    0.09812     0.03532
 6   0.05102   2   2   2   0.40000   0.60000   1.66667    0.08504     0.03061
 6   0.05567   2   2   2   0.40000   0.60000   1.66667    0.09278     0.03340
 6   0.04824   2   2   2   0.40000   0.60000   1.66667    0.08041     0.02895
 6   0.04074   2   2   2   0.40000   0.60000   1.66667    0.06791     0.02445
 6   0.05887   2   2   2   0.40000   0.60000   1.66667    0.09812     0.03532
 6   0.05567   2   2   2   0.40000   0.60000   1.66667    0.09278     0.03340
 6   0.00501   2   4   0   0.00000   1.00000   1.00000    0.00501     0.00501
 6   0.00309   2   4   0   0.00000   1.00000   1.00000    0.00309     0.00309
 6   0.00413   2   4   0   0.00000   1.00000   1.00000    0.00413     0.00413
 6   0.01193   2   4   0   0.00000   1.00000   1.00000    0.01193     0.01193
 6   0.00369   2   4   0   0.00000   1.00000   1.00000    0.00369     0.00369
 6   0.00276   2   4   0   0.00000   1.00000   1.00000    0.00276     0.00276
 6   0.01093   2   4   0   0.00000   1.00000   1.00000    0.01093     0.01093
 6   0.00530   2   4   0   0.00000   1.00000   1.00000    0.00530     0.00530
 6   0.01262   2   4   0   0.00000   1.00000   1.00000    0.01262     0.01262
 6   0.01262   2   4   0   0.00000   1.00000   1.00000    0.01262     0.01262
 6   0.00795   2   4   0   0.00000   1.00000   1.00000    0.00795     0.00795
 6   0.00841   2   4   0   0.00000   1.00000   1.00000    0.00841     0.00841
 6   0.00309   2   4   0   0.00000   1.00000   1.00000    0.00309     0.00309
 6   0.00561   2   4   0   0.00000   1.00000   1.00000    0.00561     0.00561
 6   0.00841   2   4   0   0.00000   1.00000   1.00000    0.00841     0.00841
 6   0.00651   2   4   0   0.00000   1.00000   1.00000    0.00651     0.00651
 6   0.00413   2   4   0   0.00000   1.00000   1.00000    0.00413     0.00413
 6   0.00561   2   4   0   0.00000   1.00000   1.00000    0.00561     0.00561
 6   0.00373   2   4   0   0.00000   1.00000   1.00000    0.00373     0.00373
 6   0.00295   2   4   0   0.00000   1.00000   1.00000    0.00295     0.00295
 6   0.00520   4   0   2   0.00000   1.00000   1.00000    0.00520     0.00520
 6   0.00651   4   0   2   0.00000   1.00000   1.00000    0.00651     0.00651
 6   0.00873   4   0   2   0.00000   1.00000   1.00000    0.00873     0.00873
 6   0.01034   4   0   2   0.00000   1.00000   1.00000    0.01034     0.01034
 6   0.01093   4   0   2   0.00000   1.00000   1.00000    0.01093     0.01093
 6   0.01262   4   0   2   0.00000   1.00000   1.00000    0.01262     0.01262
 6   0.00346   4   0   2   0.00000   1.00000   1.00000    0.00346     0.00346
 6   0.01193   4   0   2   0.00000   1.00000   1.00000    0.01193     0.01193
 6   0.00615   4   0   2   0.00000   1.00000   1.00000    0.00615     0.00615
 6   0.01262   4   0   2   0.00000   1.00000   1.00000    0.01262     0.01262
 6   0.01262   4   2   0   0.00000   1.00000   1.00000    0.01262     0.01262
 6   0.00795   4   2   0   0.00000   1.00000   1.00000    0.00795     0.00795
 6   0.00346   4   2   0   0.00000   1.00000   1.00000    0.00346     0.00346
 6   0.00276   4   2   0   0.00000   1.00000   1.00000    0.00276     0.00276
 6   0.00841   4   2   0   0.00000   1.00000   1.00000    0.00841     0.00841
 6   0.00413   4   2   0   0.00000   1.00000   1.00000    0.00413     0.00413
 6   0.00369   4   2   0   0.00000   1.00000   1.00000    0.00369     0.00369
 6   0.01093   4   2   0   0.00000   1.00000   1.00000    0.01093     0.01093
 6   0.00561   4   2   0   0.00000   1.00000   1.00000    0.00561     0.00561
 6   0.00651   4   2   0   0.00000   1.00000   1.00000    0.00651     0.00651
 6   0.00373   4   2   0   0.00000   1.00000   1.00000    0.00373     0.00373
 6   0.00873   4   2   0   0.00000   1.00000   1.00000    0.00873     0.00873
 6   0.00333   4   2   0   0.00000   1.00000   1.00000    0.00333     0.00333
 6   0.00309   4   2   0   0.00000   1.00000   1.00000    0.00309     0.00309
 6   0.00229   4   2   0   0.00000   1.00000   1.00000    0.00229     0.00229
 6   0.01193   4   2   0   0.00000   1.00000   1.00000    0.01193     0.01193
 6   0.00289   4   2   0   0.00000   1.00000   1.00000    0.00289     0.00289
 6   0.00561   4   2   0   0.00000   1.00000   1.00000    0.00561     0.00561
 6   0.00841   4   2   0   0.00000   1.00000   1.00000    0.00841     0.00841
 6   0.00295   4   2   0   0.00000   1.00000   1.00000    0.00295     0.00295
 6   0.01262   4   2   0   0.00000   1.00000   1.00000    0.01262     0.01262
 6   0.00473   4   2   0   0.00000   1.00000   1.00000    0.00473     0.00473
 6   0.00501   4   2   0   0.00000   1.00000   1.00000    0.00501     0.00501
 6   0.00530   4   2   0   0.00000   1.00000   1.00000    0.00530     0.00530
 6   0.01034   4   2   0   0.00000   1.00000   1.00000    0.01034     0.01034
 6   0.00413   4   2   0   0.00000   1.00000   1.00000    0.00413     0.00413
 6   0.00615   4   2   0   0.00000   1.00000   1.00000    0.00615     0.00615
 6   0.00264   4   2   0   0.00000   1.00000   1.00000    0.00264     0.00264
 6   0.00309   4   2   0   0.00000   1.00000   1.00000    0.00309     0.00309
 6   0.00520   4   2   0   0.00000   1.00000   1.00000    0.00520     0.00520
 6   0.00023   6   0   0   0.00000   1.00000   1.00000    0.00023     0.00023
 6   0.00035   6   0   0   0.00000   1.00000   1.00000    0.00035     0.00035
 6   0.00040   6   0   0   0.00000   1.00000   1.00000    0.00040     0.00040
 6   0.00028   6   0   0   0.00000   1.00000   1.00000    0.00028     0.00028
 6   0.00042   6   0   0   0.00000   1.00000   1.00000    0.00042     0.00042
 6   0.00033   6   0   0   0.00000   1.00000   1.00000    0.00033     0.00033
 6   0.00028   6   0   0   0.00000   1.00000   1.00000    0.00028     0.00028
 6   0.00042   6   0   0   0.00000   1.00000   1.00000    0.00042     0.00042
 6   0.00062   6   0   0   0.00000   1.00000   1.00000    0.00062     0.00062
 6   0.00062   6   0   0   0.00000   1.00000   1.00000    0.00062     0.00062
 6   0.00057   6   0   0   0.00000   1.00000   1.00000    0.00057     0.00057
 6   0.00074   6   0   0   0.00000   1.00000   1.00000    0.00074     0.00074
 6   0.00074   6   0   0   0.00000   1.00000   1.00000    0.00074     0.00074
 6   0.00032   6   0   0   0.00000   1.00000   1.00000    0.00032     0.00032
 6   0.00044   6   0   0   0.00000   1.00000   1.00000    0.00044     0.00044
 6   0.00060   6   0   0   0.00000   1.00000   1.00000    0.00060     0.00060
 6   0.00078   6   0   0   0.00000   1.00000   1.00000    0.00078     0.00078
 6   0.00027   6   0   0   0.00000   1.00000   1.00000    0.00027     0.00027
 6   0.00078   6   0   0   0.00000   1.00000   1.00000    0.00078     0.00078
 6   0.00018   6   0   0   0.00000   1.00000   1.00000    0.00018     0.00018

Comparison with simulation:

The situation is simulated by:

DECLARE SUB returnSock (s#)
DEFDBL A-Z
RANDOMIZE TIMER
FOR week = 1 TO 5000
  socks = 16
  blue = 8: black = 6: brown = 2
  FOR day = 1 TO 6
    tryct = 0: match = 0
    WHILE match = 0
     r1 = INT(socks * RND(1) + 1)
     DO
       r2 = INT(socks * RND(1) + 1)
     LOOP UNTIL r2 <> r1
     DO
       r3 = INT(socks * RND(1) + 1)
     LOOP UNTIL r3 <> r1 AND r3 <> r2
     IF r1 <= blue THEN
       c1 = 1
     ELSEIF r1 <= blue + black THEN
       c1 = 2
     ELSE
       c1 = 3
     END IF
     IF r2 <= blue THEN
       c2 = 1
     ELSEIF r2 <= blue + black THEN
       c2 = 2
     ELSE
       c2 = 3
     END IF
     IF r3 <= blue THEN
       c3 = 1
     ELSEIF r3 <= blue + black THEN
       c3 = 2
     ELSE
       c3 = 3
     END IF
     SELECT CASE c1
        CASE 1: blue = blue - 1
        CASE 2: black = black - 1
        CASE 3: brown = brown - 1
     END SELECT
     SELECT CASE c2
        CASE 1: blue = blue - 1
        CASE 2: black = black - 1
        CASE 3: brown = brown - 1
     END SELECT
     SELECT CASE c3
        CASE 1: blue = blue - 1
        CASE 2: black = black - 1
        CASE 3: brown = brown - 1
     END SELECT
     tryct = tryct + 1
     IF c1 = c2 THEN
       returnSock c3: match = 1
     ELSEIF c1 = c3 THEN
       returnSock c2: match = 1
     ELSEIF c2 = c3 THEN
       returnSock c1: match = 1
     ELSE
       returnSock c1: returnSock c2: returnSock c3
     END IF
     IF day = 1 THEN PRINT c1; c2; c3
    WEND
    socks = socks - 2
    tries(day) = tries(day) + tryct
    IF tryct = 1 THEN onetry(day) = onetry(day) + 1
    IF day = 1 THEN
     PRINT tryct, blue; black; brown, tries(day) / week
     '
    END IF
  NEXT day
NEXT week
week = week - 1
FOR i = 1 TO 6
    PRINT USING "###.#####"; tries(i) / week; onetry(i) / week
NEXT: PRINT

SUB returnSock (s)
  SHARED blue, black, brown
  SELECT CASE s
    CASE 1: blue = blue + 1
    CASE 2: black = black + 1
    CASE 3: brown = brown + 1
  END SELECT
END SUB

 

which simulates 5000 weeks--almost 100 years (95.8 years to be almost exact). The results (average number of tries to get a pair) of one particular run, as the random generator is randomized by the timer for a particular run, are:

avg length avg. prob.
  1.20640  0.83000
  1.22860  0.81520
  1.24380  0.80460
  1.30080  0.77940
  1.32280  0.77140
  1.35420  0.78880

 
in good agreement with the calculated probabilities.

 


  Posted by Charlie on 2013-06-28 18:57:50
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


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

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