It has to do with cards. A deck of cards has 52 cards and a single
card can have 4 different suits and 13 different values.
I drawing two cards, obiously they cant be exactly simular. Also im
ignoring the order of the cards im drawing.
e.g.
52*51 / 2! = 1326 different hands
A single card can be looked upon like this:
{Suit, Value}
fx.
NB! im using ranges starting from zero fx. 0-3 instead of 1-4.
{3,12} & {3,11}
This hand would equal Ace King or Queen King in the same suit,
dependent on Ace being assigned lowest or highest value, but it doesnt
matter here.
The goal is to somehow calculate this specific hands unique patter in
the range of 0-1325.
Of course this can be done, quite easily all though the soltion to the
problem illudes me, but im allso interested in different ways of doing
it as im confident that it is possible to derive various information
from this patter if done proberbly, fx. if the cards are suited,
connected or both, or if a pair is present.
If my assumption is incorrect i will still need the solution though.
Allso i need a generel solution for hands with up to 7 cards. 7 cards
however is the limit.
NB! The ability to derive the actual values and suit of the cards
later on is NOT important.
I hope you can and will help me.
Regards
If you number the cards from 1 to 52 (however you choose) and order
the hand by ascending card number, then I think the formula I gave
recently at http://groups.google.com/group/sci.math/browse_frm/thread/eb65d32877f11001.
for converting combinations to "sequence numbers" might do what you
need. For each unique hand it should give you a corresponding unique
"hand number". You would need n = 52 and k = number of cards in hand.
You would need to subtract one if you want the hand numbering to start
at zero.
thanks, ill look at it.
is this the answer you are talking about?
C(n, k) - sum_j=1^k C(n - x(j), k - j + 1)
if that is the case i dont quite understand it.
Im fairly good at math, but when it comes to this im lost.
Yes. There's a post in that thread at http://groups.google.com/group/sci.math/msg/ba950279560ed270
which gives an explanation of what the formula means, along with an
example of how to apply it. See if that makes any sense.
I cant say i understand this, but i do understand that 52! is a HUGE
number, so enless i have misinterpeted something, this is not useable.
C(x, y) = x!/(y!*(x - y)!)
52! is indeed a huge number, but C(52,k) is not huge for small k (and
if you have large k -- i.e. large hands -- then you inevitably will be
dealing with huge numbers because there are so many different hands).
The way I wrote the definition above is the usual way, but you do not
actually need to calculate 52! because large chunks of the numerator
and denominator cancel. Specifically:
C(52,1) = 52/1!
C(52,2) = 52*51/2!
C(52,3) = 52*51*50/3!
C(52,4) = 52*51*50*49/4!
etc.
ok, so in this case C(n,k) = 1326, that i can understand.
the formula:
C(n, k) - sum_j=1^k C(n - x(j), k - j + 1)
however still doesnt make sence, ive tryed to read your post again and
again and i would hate to make you explain it again, but so far i dont
get it. I will try again though.
It shouldn't be too hard. In your first example, with hands of two
cards, we have n = 52 and k = 2. You know how to calculate C(n, k), so
that takes care of the first term.
Then, for each value of j from j = 1 to j = k (i.e. in this case, just
for j = 1 and j = 2), calculate C(n - x(j), k - j + 1), where x(1) is
the number of the first card in the hand (cards numbered 1 to 52, in
whatever way you choose), and x(2) is the number of the second card,
with x(1) < x(2).
Add all these terms (in this case just two of them) together, subtract
the sum from C(n, k), and you're done.
Good luck.
Oh, except that if you want the hands numbered from 0 to 1325 (rather
than 1 to 1326) you will need to subtract 1.
Thank you, just have to do something and then ill try it out.
This is the result i arive at when using cards 52 and 51 as an
example, i do this because i expect to get 1326 as a result:
C(52,2) - C(52 - 51, 2 - 1 + 1) + C(52 - 52, 2 - 2 + 1)
(52*51 / 2!) - C(1, 2) + C(0, 1)
(52*51 / 2!) - (1*0 / 2!) + (0 / 1!)
1326 - 0 + 0
1326
seem right.
Doing it with the lowest possible values, 1 and 2, where i expect to
get the result 1:
C(52,2) - C(52 - 1, 2 - 1 + 1) + C(52 - 2, 2 - 2 + 1)
(52*51 / 2!) - C(51, 2) + C(50, 1)
(52*51 / 2!) - (51*50 / 2!) + (50 / 1!)
1326 - 1275 + 50
1
again it seems to work.
first i didnt see the "x(1) < x(2)" comment and did it wrong.
It is enoying that hte order of the values does matter, but you cant
get it all i supose.
Thank you for your help.
Okay, we need to map all possible pairs of cards
to a number between 0 and 1325.
> A single card can be looked upon like this:
> {Suit, Value}
> fx.
> NB! im using ranges starting from zero fx. 0-3 instead of 1-4.
>
> {3,12} & {3,11}
The mapping from (Suit,Value) to a number between 0 and 51 is
Suit + Value*4 (assuming Suit is 0 to 3 & Value is 0 to 13).
> This hand would equal Ace King or Queen King in the same suit,
> dependent on Ace being assigned lowest or highest value, but it doesnt
> matter here.
>
> The goal is to somehow calculate this specific hands unique patter in
> the range of 0-1325.
[snip]
We have two distinct numbers, by the mapping above, between
0 and 51. Obviously one is bigger than the other, say m > n.
If n < 25, let m + n*52 represent the pair.
If n >= 25, let (51-m) + (50-n)*52 represent the pair.
It should be clear that the smallest value represented
here is 0 (from m = 51, n = 50). The largest value is
for n = 25 so that the coefficient of 52 is maximized,
and m = 26:
(51-26) + (50-25)*52 = 25 + 25*52 = 1325
The range of representations is 0 to 1325, as desired.
Such a formulation can be extended, albeit awkwardly,
to higher dimensions/larger card hands.
regards, chip
thanks
Do you want an ordering of them which knows about the rules of poker? So
four example a pair of two's is higher than a King and Jack of different
suits?
If so, you are going to have to do this the hard way.
Find all the straight flushes (there are 48 of them), and number them from
1325 down.
From the remaining combinations, find all the straights, and number them
from 1277 down
From all the remaining combinations, find all the straights and number them
down
From the remaining combinations, find all the pairs and number them down
With the remaining combinations (of two unrelated cards), number them down
(to zero, hopefully).
Alternatively, you could bubble sort a list of all 1326 combinations using
the rules of poker to decide which of the two pairs is higher.
>It has to do with cards. A deck of cards has 52 cards and a single
>card can have 4 different suits and 13 different values.
>A single card can be looked upon like this:
>{Suit, Value}
So far you're okay. Every card will be represented by a unique set.
>NB! im using ranges starting from zero fx. 0-3 instead of 1-4.
Right here, though, by mapping suits and values to numbers, you've
caused yourself a problem. (Technically, it's because you've chosen
overlapping ranges of integers.)
Since there's no difference between the set {2,3} and the set {3,2},
you have a bit of a problem with this representation. I'd suggest
that, if you need to map suits and values to integers, you should
use ordered pairs rather than sets.
--
Michael F. Stemper
#include <Standard_Disclaimer>
Outside of a dog, a book is man's best friend.
Inside of a dog, it's too dark to read.
As an afterthought... the formula I referred you to from the other
thread was constructed specifically so as to number the combinations
(in your case hands) in ascending order. I kind of forgot that wasn't
necessarily a requirement for you. If that requirement is dropped I
think the formula can be simplified to just
sum_j=1^k C(x(j) - 1, j)
with the all the symbols having the same meaning as before.
You get a unique number in the correct range for each hand but they
aren't ordered in any especially helpful way (kind of "reverse
reverse" order). Again this works for any k, not just k = 2.