Thread View: sci.math.num-analysis
1 messages
1 total messages
Started by Peter Pui Tak Chiu
Sun, 13 Sep 1992 18:52
FULL HOUSE (REVISED)
Author: Peter Pui Tak Chiu
Date: Sun, 13 Sep 1992 18:52
Date: Sun, 13 Sep 1992 18:52
56 lines
1518 bytes
1518 bytes
// 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";
}}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads