home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1168 < prev    next >
Encoding:
Text File  |  1992-09-13  |  2.7 KB  |  101 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!gumby!wupost!eclnews!cec1!ppc1
  3. From: ppc1@cec1.wustl.edu (Peter Pui Tak Chiu)
  4. Subject: FULL HOUSE
  5. Message-ID: <1992Sep13.144341.24950@wuecl.wustl.edu>
  6. Sender: usenet@wuecl.wustl.edu (Usenet Administrator)
  7. Nntp-Posting-Host: cec1
  8. Organization: Washington University, St. Louis MO
  9. Date: Sun, 13 Sep 1992 14:43:41 GMT
  10. Lines: 89
  11.  
  12.  
  13. hi everyone,
  14.  
  15. i am trying to find the probability of getting a hand of full house from a
  16. shuffled deck of 52 cards.
  17.  
  18. theoretically, the probability (i think) is:
  19.  
  20.         (13 * 4C2) * (12 * 4C3)
  21.         -----------------------  =  0.001440576
  22.                  52C5
  23.  
  24. but i wrote a c program to calculate this probability and the results turn
  25. out to be very different.
  26.  
  27. here is part of the results i have:
  28.  
  29. * the first column denotes the number of trials
  30. * the second column denotes the probability obtained so far
  31.  
  32.  
  33. 5400000 0.00420815
  34. 5410000 0.00420758
  35. 5420000 0.00420867
  36. 5430000 0.00420829
  37. 5440000 0.00420937
  38. 5450000 0.00421046
  39. 5460000 0.00421154
  40. 5470000 0.00420987
  41. 5480000 0.00420967
  42. 5490000 0.00420765
  43. 5500000 0.004208  ..... this means after 5500000 trials, the prob. is 0.004208
  44.  
  45.  
  46. from these results, i conclude that the probability would be pretty much around
  47. 0.00421 which is very different from the theoretical value.
  48.  
  49. does anyone know why???
  50.  
  51. i have included the program i wrote.  it is written in C++ and is very crude...
  52. please try it and give me some feedback.
  53.  
  54. thanx a lot!
  55.  
  56. pete
  57.  
  58.  
  59. // To calculate the probability of getting a full house
  60.  
  61. #include <iostream.h>
  62. #include <time.h>
  63. #include <stdlib.h>
  64. #include <math.h>
  65.  
  66. int BAD,hand[5];        // BAD when the hand dealt is illegal
  67.                 // e.g. 5 of the same kind.
  68.                 // hand is an array holding the cards dealt
  69. long COUNTER=0, GOOD=0;        // COUNTER = # of trials
  70.                 // GOOD = # of full house dealt
  71.  
  72.  
  73. void init(){
  74. for(int i=0;i<5;i++)hand[i]=rand()%13;    // deal the cards
  75. }
  76.  
  77. int fullhouse(){            // determine if fullhouse or illegal
  78. int counter[13],flag3=0,flag2=0;
  79. BAD=0;
  80. for(int i=0;i<13;i++)counter[i]=0;
  81. for(i=0;i<5;i++)counter[hand[i]]++;
  82. for(i=0;i<13;i++){
  83.     if(counter[i]==3)flag3++;    // detect for 3 of a kind
  84.     if(counter[i]==2)flag2++;    // detect for a pair
  85.     if(counter[i]>4)BAD=1;}        // detect for a bad hand
  86. return((flag3==1) && (flag2==1));
  87. }
  88.  
  89. main(){
  90. srand((unsigned)time(NULL));        // initialize random seed
  91. while(1){
  92. init();                    // deal the cards
  93. if(fullhouse())GOOD++;            // if a FULLHOUSE is dealt, increment
  94.                     // GOOD
  95. if(!BAD)COUNTER++;            // if the hand dealt is legal
  96.                     // increment COUNTER
  97. if(!fmod(COUNTER,10000))cerr<<COUNTER<<" "<<double(GOOD)/COUNTER<<"\n";
  98.     // print out the result every 10000 trials in the format:
  99.     // [ # of trials ] [ probability obtained so far to get full house ]
  100. }}
  101.