Update: Tough C++ nut to crack

Jun 18, 2000
11,216
781
126
Update: Ok here's my new problem.

Using a Monte Carlo simulation, estimate the possibility of getting a "Full House" (three cards of the same rank plus a par, also matching in rank) on a random deal out of a deck of 52 cards (4 suits, 13 cards of different ranks in each suit). Compare your estimate with the theoretical result, 6/4165.

I remember what the Monte Carlo method is, but I'm having a hard time coming up with a algorith to solve the problem.
 

Pretender

Banned
Mar 14, 2000
7,192
0
0
apstring is just a class made up by the AP College Board because they think letting people use real strings would be too dangerous.
 
Jun 18, 2000
11,216
781
126
Ughh. I don't necessarily need the code. I don't get how I'm going to set the program up.

Am I going to need an enumerated data type?

enum suit { DIAMOND, HEART, SPAID, CLUB };

Then I know I'm going to need to set up an apvector of type suit.

apvector<suit> possibleCards(52);

or should I set up the apvector to handle the 5 card draw (replace the 52 with 5). Geez this one is going to take me a while.
 

Pretender

Banned
Mar 14, 2000
7,192
0
0
Is the program supposed to calculate the probability using a combination formula (I don't remember the exact calculation, that was last yrs math for me), or by randomly choosing 5 cards continuously until it comes upon a full house, then output the probability based on the number of tries it took?
 
Jun 18, 2000
11,216
781
126
Pretender, your guess is as good as mine. The problem is typed out word-for-word in my first post (its copied directly off the worksheet).

I'm still working out the algorithm. :eek:
 

hans007

Lifer
Feb 1, 2000
20,212
18
81
oh the combination forumula is n! /r!(n-r)! something like that. You are gonna have to write a factorialing function should be real easy. r up there is the number of options, n is the number of things you will pick. its a pretty tought problem i guess, if this were my own project i'd work on it, but its not. But if you have a factorial function and the combination forumula you should be able to do it. I think its just the probability of choosing 3 of a kind of a card * the probability of getting a pair.
 

br0wn

Senior member
Jun 22, 2000
572
0
0
I think you are supposed to run a Monte Carlo simulation.

Basically, randomly picked 52 cards for about n times (n
should be big, like 100,000 or more), and then record
how many times you come up with a Full House.
The probability calculated from your program should be
= # of Full House / n

Compare the result that you get from the program with theoretical
result which is 6/4165.