4

I want to pick the top "range" of cards based upon a percentage. I have all my possible 2 card hands organized in an array in order of the strength of the hand, like so:

```
AA, KK, AKsuited, QQ, AKoff-suit ...
```

I had been picking the top 10% of hands by multiplying the length of the card array by the percentage which would give me the index of the last card in the array. Then I would just make a copy of the sub-array:

```
Arrays.copyOfRange(cardArray, 0, 16);
```

However, I realize now that this is incorrect because there are more possible combinations of, say, Ace King off-suit - 12 combinations (i.e. an ace of one suit and a king of another suit) than there are combinations of, say, a pair of aces - 6 combinations.

When I pick the top 10% of hands therefore I want it to be based on the top 10% of hands in proportion to the total number of 2 cards combinations - 52 choose 2 = 1326.

I thought I could have an array of integers where each index held the combined total of all the combinations up to that point (each index would correspond to a hand from the original array). So the first few indices of the array would be:

```
6, 12, 16, 22
```

because there are 6 combinations of AA, 6 combinations of KK, 4 combinations of AKsuited, 6 combinations of QQ.

Then I could do a binary search which runs in BigOh(log n) time. In other words I could multiply the total number of combinations (1326) by the percentage, search for the first index lower than or equal to this number, and that would be the index of the original array that I need.

I wonder if there a way that I could do this in constant time instead?

2Since 1326 is not such a large number, why don't you simply precreate all tuples and store them in a sorted array? – Groo – 2011-12-22T14:06:57.443

Do you mean that I have a 2 dimensional array of length 1326 in one dimension and in the other it would have an array of the card range? So the first index would have an array of one hand "AA" and the last index would have an array containing all the hands possible. How would this data structure normally be initialized in software. I use Java, so I can either type it in as a literal - NO, construct in programatically in the constructor and make sure that I keep that object alive so I only have to do it once, or read it in from a file at the start of the program. Thanks for your comment. – Joe – 2011-12-22T14:29:08.853

I was thinking of a 1-dimensional array with

allcombinations sorted sequentially. There is 1326 ways to choose two cards from a 52 card deck, so simply create all combinations and sort them. – Groo – 2011-12-22T14:36:05.943@Joe: note that there's no such thing as an accepted, say,

"top 15%"of hands. There are different ways to rank starting Texas Hold'em holecards: Sklansky & Malmuth is one of the most common. You could also run every pair of cards vs any other possible pair (and you'd end up with different "top 15%") or (and it has been done), you could takebillionsof actually played hands and see which holecards netted which result and you'd end up with yet another result for the hypothetic"top 15%". – TacticalCoder – 2011-12-24T14:54:39.317