As there are 52 cards in a deck we know there are 52 choose 2 = 1326
distinct matchups, however in preflop poker this can be bucketed into 169 different hands such as AK offsuit and AK suited as whether it is A hearts K hearts or A spade K spades it makes no difference preflop. My question is, is there a nice mathematical property in which I can uniquely index each of these 169 hands (from 0 to 168 preferably). I am trying to create a look up table as a double[][] = new double [169][169]
but have no way of changing a hand representation such as AKs (an Ace and a King of the same suit) to a unique index in this array.
views:
197answers:
1
+2
A:
- If the cards are of the same suit, sort the two cards, so that the lower card comes first. If they are of different suits, sort the two cards so that the lower card comes last. A special case will be reserved for when the cards are of the same rank and suit.
- Assign each rank a value from 0 to 12 and use a base-13 counting system. The highest value in this system is 12*13 + 12 = 168.
- Finally, for cases where both cards are of the same rank and suit, take the value of the rank and add 169 to it. These cases will be in the range 169-181.
Maybe my math is wrong, but I come up with 182 distinct pairs of cards. I'm no expert in the game, so maybe I'm missing something.
Ben Hocking
2010-03-15 23:56:35
Sounds pretty correct and we shall never have 2 of the same card (as only one of each card exist in a standard deck)
Aly
2010-03-16 00:01:32
Let 0-9 represent 0-9, A=10, B=11, and C=12. Those are our digits. In base-13, you could have B3, which would be converted to decimal as B (i.e., 11) times 13 + 3, or 146. Does that make sense?
Ben Hocking
2010-03-16 00:07:43
Oh, and your answer about not having two of the same card seems obvious now that you explained it. :)'(I could play innocent and claim I was assuming multiple decks, but I just wasn't thinking it through at all.)
Ben Hocking
2010-03-16 00:08:51
Yup, thanks I think I've got it. Much appreciated!
Aly
2010-03-16 00:13:05
My pleasure. It was a fun little exercise.
Ben Hocking
2010-03-16 00:15:06
Two cards of the same rank and suit? That's not possible unless you're playing with multiple decks.
Nick Johnson
2010-09-30 09:37:36