home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / programm / 2600 < prev    next >
Encoding:
Text File  |  1992-09-13  |  1.4 KB  |  70 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!spool.mu.edu!wupost!eclnews!cec1!ppc1
  3. From: ppc1@cec1.wustl.edu (Peter Pui Tak Chiu)
  4. Subject: FULL HOUSE (REVISED)
  5. Message-ID: <1992Sep13.223147.28768@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 22:31:47 GMT
  10. Lines: 58
  11.  
  12.  
  13.  
  14. // this previous version of this program assumes that we are drawing from
  15. // an infinite deck.  (which is a bug).
  16.  
  17. // now this version has no such problem...
  18. // but still the probability is around 0.004...
  19. // which is four times the theoretical value 0.001441
  20.  
  21. // what's wrong???!!!
  22.  
  23. #include <iostream.h>
  24. #include <time.h>
  25. #include <stdlib.h>
  26. #include <math.h>
  27.  
  28. static int hand[5];
  29. long COUNTER=0, GOOD=0;
  30.  
  31. int getRandom(){
  32. int n,BAD=1;
  33. while(BAD){
  34. n=rand()%52+1;
  35. for(int i=0;i<5;i++){
  36.     int FLAG=0;
  37.     if(n==hand[i])FLAG=1;
  38.     if(!FLAG)BAD=0;
  39.     }}
  40. return(n);
  41. }
  42.  
  43. void init(){
  44. for(int i=0;i<5;i++)hand[i]=0;
  45. for(i=0;i<5;i++)hand[i]=getRandom();
  46. for(i=0;i<5;i++)hand[i]=hand[i]%13;
  47. }
  48.  
  49. int fullhouse(){
  50. int counter[13],flag2=0,flag3=0;
  51. for(int i=0;i<13;i++)counter[i]=0;
  52. for(i=0;i<5;i++)counter[hand[i]]++;
  53. for(i=0;i<13;i++){
  54.     if(counter[i]==2)flag2++;
  55.     if(counter[i]==3)flag3++;
  56.     }
  57. return(flag2&&flag3);
  58. }
  59.  
  60. main(){
  61. randomize();
  62. while(1){
  63. COUNTER++;
  64. init();
  65. if(fullhouse())GOOD++;
  66. if(!fmod(COUNTER,10000))cerr<<COUNTER<<double(GOOD)/COUNTER<<"\n";
  67. }}
  68.  
  69.  
  70.