Thread View: comp.std.c++
3 messages
3 total messages
Started by Peter Pui Tak Chiu
Sun, 13 Sep 1992 14:43
FULL HOUSE
Author: Peter Pui Tak Chiu
Date: Sun, 13 Sep 1992 14:43
Date: Sun, 13 Sep 1992 14:43
89 lines
2835 bytes
2835 bytes
hi everyone,
i am trying to find the probability of getting a hand of full house from a
shuffled deck of 52 cards.
theoretically, the probability (i think) is:
(13 * 4C2) * (12 * 4C3)
----------------------- = 0.001440576
52C5
but i wrote a c program to calculate this probability and the results turn
out to be very different.
here is part of the results i have:
* the first column denotes the number of trials
* the second column denotes the probability obtained so far
5400000 0.00420815
5410000 0.00420758
5420000 0.00420867
5430000 0.00420829
5440000 0.00420937
5450000 0.00421046
5460000 0.00421154
5470000 0.00420987
5480000 0.00420967
5490000 0.00420765
5500000 0.004208 ..... this means after 5500000 trials, the prob. is 0.004208
from these results, i conclude that the probability would be pretty much around
0.00421 which is very different from the theoretical value.
does anyone know why???
i have included the program i wrote. it is written in C++ and is very crude...
please try it and give me some feedback.
thanx a lot!
pete
// To calculate the probability of getting a full house
#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
int BAD,hand[5]; // BAD when the hand dealt is illegal
// e.g. 5 of the same kind.
// hand is an array holding the cards dealt
long COUNTER=0, GOOD=0; // COUNTER = # of trials
// GOOD = # of full house dealt
void init(){
for(int i=0;i<5;i++)hand[i]=rand()%13; // deal the cards
}
int fullhouse(){ // determine if fullhouse or illegal
int counter[13],flag3=0,flag2=0;
BAD=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]==3)flag3++; // detect for 3 of a kind
if(counter[i]==2)flag2++; // detect for a pair
if(counter[i]>4)BAD=1;} // detect for a bad hand
return((flag3==1) && (flag2==1));
}
main(){
srand((unsigned)time(NULL)); // initialize random seed
while(1){
init(); // deal the cards
if(fullhouse())GOOD++; // if a FULLHOUSE is dealt, increment
// GOOD
if(!BAD)COUNTER++; // if the hand dealt is legal
// increment COUNTER
if(!fmod(COUNTER,10000))cerr<<COUNTER<<" "<<double(GOOD)/COUNTER<<"\n";
// print out the result every 10000 trials in the format:
// [ # of trials ] [ probability obtained so far to get full house ]
}}
Re: FULL HOUSE
Author: Fergus James HENDERSON
Date: Sun, 13 Sep 1992 15:49
Date: Sun, 13 Sep 1992 15:49
18 lines
1207 bytes
1207 bytes
ppc1@cec1.wustl.edu (Peter Pui Tak Chiu) writes: >hi everyone, > >i am trying to find the probability of getting a hand of full house from a >shuffled deck of 52 cards. This post does not belong in comp.std.c++. comp.std.c++ is for discussion of standarization issues with regard to the C++ language, not for general programming questions. I have posted a follow-up in comp.programming. -- Fergus Henderson fjh@munta.cs.mu.OZ.AU This .signature virus is a self-referential statement that is true - but you will only be able to consistently believe it if you copy it to your own .signature file!
Re: FULL HOUSE
Author: Karl Heuer
Date: Mon, 14 Sep 1992 07:34
Date: Mon, 14 Sep 1992 07:34
8 lines
848 bytes
848 bytes
In article <1992Sep13.144341.24950@wuecl.wustl.edu> ppc1@cec1.wustl.edu (Peter Pui Tak Chiu) writes: >for(int i=0;i<5;i++)hand[i]=rand()%13; // deal the cards I would say you're not playing with a full deck. (Incidentally, your article has nothing to do with the process of standardizing the C++ language. Perhaps comp.programming would be a better place to ask this sort of question.)
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