Hi, I am taking a intro to C++ course so my knowledge base only limits to areas such as if/else, functions, and recursions.
We are creating a program which will determine the probability of Poker Hands, such as Royal Flush, Straight Flush, Four of a Kind and such. However in order to complete this, I need to determine how many different poker hands there are. On pencil and paper, this is relatively easy as its a simple combination problem.
52! / 5! 47!
52 represents the deck, 5 represents the hand, and 47 represent the DeckHand. The total amount of poker hands are 2,598960.
The problem is that I cant seem to implement this into my program. I cannot simply pull a random number such as 2,598960 out of thin air. I must prove it within the confines of my program with the use of combinations. Thus far, I have attempted to use a recursion for the numerator and denominator. This is not successful as 50! well exceeds the any type of data type.
In real life, there is a cancellation for simplicity which results to 52x51x50x49x48/5x4x3x2x1. This would be much easier for the program to calculate. However I doubt there is a way for the program to perform cancellations.
In general, I am having a hard time initializing this program simply because I dont know how to force the program to perform such calculations. Any help is appreciated.
7 5616
In my opinion, it's possible to make a computer program do anything. That's probably not very reassuring. But if you can think of an algorithm for it, you can code it. Your program should be able to preform cancellations. I can think of one way to do this now, although it would not be very efficient. Every time you multiply the result by one of the huge numbers, loop through all the numbers you're dividing it by to see if it's divisible by any of them yet If it is, divide, and then scratch that number from the list. Oh wait... You don't have a list. Has your class covered arrays or vectors yet?
Good luck.
You don't need arrays or anything like that. Cancellations can be done much more easily than you think.
First, I think you already have the recursive function that calculates the factorial of an integer. So you will use this function for the small denominator(which is 5 in your example).
You will have to write another function too, call it cancellation. It should take two parameters. The first one is the large numerator(which is 52 in you example), and the second one is the larger denomenator(which is 47 in your example). This function will be very similar to the factorial function, except for the if statement that is used in the factorial function to stop the recursivity(which is something like: if(n>1)). Instead the if statement should be: if(n>q) (or if(52>47) in your example) and that should stop the recursive multiplication at nq (at 48 in your example). And remember to change the first parameter only, as the second parameter stays constant throughout the recursivity( meaning you should write:
if(n>q) return(n*cancellation(n1,q)) );
And in main all you have to do is divide the return value of cancellation by the return value of factorial(where factorial takes the small denominator as parameter ofcourse).
The combination is the denominator for the probability. Don't stall out while you're waiting to figure out how to compute that denominator value  try to compute the numerator values for various poker hands. That is, the number of distinct combinations of cards in your hand that all amount to a particular poker hand. You can manually verify a few of these to see your calculations are correct.
Instead of recursion, does anyone know how to implement a factorial/permutation/combination for looping instead?
Such as 52! / 5! 47!
The algorithm seems to be n * (n  1) * (n  2) * (n  3).....and so forth
Recursion may be the way to go, however, keep in mind that a!/b! = (a*a1*a2*...*b+1) if a > b, since a! = a*a1*a2*...*1 and b = b*b1*b2*...*1.
For example, 5!/3!: (5*4*3*2*1)/(3*2*1) cancels to 5*4.
Implementing this in code is up to you, however.
As mentioned above, you'll need a function which computes the factorial down to a certain number, perm(n,r) = n!/(nr)! = n(n1)(n2)...(n(r1)). This can be achieved with a recursive function call, for example:
< spoonfeeding code deleted >
In this way, a permutation nPr is simply perm(n,r), and a combination or binomial coefficient nCr is perm(n,r)/perm(r,1).
You can even go a bit further if you note that a sequence of n adjacent numbers
contains one number that can be divided by n itself. So, e.g. 52C5 = 52!/5!/(525)!
== 52*51*50*49*48/1*2*3*4*5 == 48/1*49/2*50/3*51/4*52/5. Note that divisions
are always exact and the intermediate results are always as small as possible.
One single loop can do the job here.
kind regards,
Jos
ps. I ostensibly removed the spoonfeeding code in previous replies; I personally
don't agree with this but I'll continue the discussion about this matter in the
ongoing thread somewhere else. There should be a 'modus operandi' for answering
a question by using a code fragment.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andreas Schmitt 
last post by:
Hi,
Sorry for posting in German before, totally forgot about that when I was
pasting this in here from another German newsgroup I was writing to, trying
to get help
I am programming a simple...

by: ibtc209 
last post by:
I just started programming in C, and I need some help with this problem.
Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s
first card, and...

by: Martin Olsen 
last post by:
Hi all.
I am creating a program which calculates poker odds. The program should
look at the visible cards (those on your hand and those on the table)
then count the cards needed to improve the...

by: Simon Biber 
last post by:
I was reading http://en.wikipedia.org/wiki/Poker_probability which has a
good description of how to count the frequency of different types of
poker hands using a mathematical approach. A sample...

by: hardieca 
last post by:
Has anyone heard of an opensource .NET engine that calculates the
winning and losing percentages of hands?
Regards,
Chris

by: sandy123456 
last post by:
At the moment im trying to write a hand class for a game poker patientnce
But when i get to the part having to catergorise the difference of full house straight flush flush four of a kind and...

by: kinghippo423 
last post by:
Hello Everyone,
I did a poker program in Java that essencially finds the strenght of a poker hand created Randomly. My program is doing OK...but I'm pretty sure it can be optimised.
This is my...

by: bnashenas1984 
last post by:
Hi every one
I'm trying to make a little poker game but I don't know how to evaluate the strength of a 7 card hand..
It's not that hard with 5 cards. Actually I found some program to do that with...

by: teejayem 
last post by:
I am looking for some help!
I am currently developing a new game for an online community. The
game is called Pokino which ishalf bingo and half poker. Wierd eh?!
Anyway...
The final part...

by: veera ravala 
last post by:
ServiceNow is a powerful cloudbased platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...

by: VivesProcSPL 
last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many Englishlike terms and syntax in an effort to make it easy to learn, particularly for...

by: mar23 
last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...

by: abbasky 
last post by:
### Vandf component communication method one: data sharing
Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...

by: jimatqsi 
last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...

by: isladogs 
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...

by: stefan129 
last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multidomain SSL certificates? Any recommendations on reliable providers or specific...

by: egorbl4 
last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это
Что это? Что мне с этим делать?
...

by: MeoLessi9 
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
 