home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!spool.mu.edu!wupost!eclnews!cec1!ppc1
- From: ppc1@cec1.wustl.edu (Peter Pui Tak Chiu)
- Subject: FULL HOUSE (REVISED)
- Message-ID: <1992Sep13.223147.28768@wuecl.wustl.edu>
- Sender: usenet@wuecl.wustl.edu (Usenet Administrator)
- Nntp-Posting-Host: cec1
- Organization: Washington University, St. Louis MO
- Date: Sun, 13 Sep 1992 22:31:47 GMT
- Lines: 58
-
-
-
- // this previous version of this program assumes that we are drawing from
- // an infinite deck. (which is a bug).
-
- // now this version has no such problem...
- // but still the probability is around 0.004...
- // which is four times the theoretical value 0.001441
-
- // what's wrong???!!!
-
- #include <iostream.h>
- #include <time.h>
- #include <stdlib.h>
- #include <math.h>
-
- static int hand[5];
- long COUNTER=0, GOOD=0;
-
- int getRandom(){
- int n,BAD=1;
- while(BAD){
- n=rand()%52+1;
- for(int i=0;i<5;i++){
- int FLAG=0;
- if(n==hand[i])FLAG=1;
- if(!FLAG)BAD=0;
- }}
- return(n);
- }
-
- void init(){
- for(int i=0;i<5;i++)hand[i]=0;
- for(i=0;i<5;i++)hand[i]=getRandom();
- for(i=0;i<5;i++)hand[i]=hand[i]%13;
- }
-
- int fullhouse(){
- int counter[13],flag2=0,flag3=0;
- for(int i=0;i<13;i++)counter[i]=0;
- for(i=0;i<5;i++)counter[hand[i]]++;
- for(i=0;i<13;i++){
- if(counter[i]==2)flag2++;
- if(counter[i]==3)flag3++;
- }
- return(flag2&&flag3);
- }
-
- main(){
- randomize();
- while(1){
- COUNTER++;
- init();
- if(fullhouse())GOOD++;
- if(!fmod(COUNTER,10000))cerr<<COUNTER<<double(GOOD)/COUNTER<<"\n";
- }}
-
-
-