Open Side Menu Go to the Top
Register
Dealing pairs routine Dealing pairs routine

12-26-2017 , 04:13 PM
Need a software routine, preferably in Visual Basic. Assume N players and each is dealt a pair from a standard deck (N <=5) . Want to output for each rank the number of players that have that pair. Thus, the value for each rank is 0, 1, or 2. There are initially 6 combinations for each rank and that number reduces to 1 if a player is dealt that pair. An output for N=5 might be, 1 player has a 4 pair, 1 a 6 pair, 2 each have a pair of tens, and 1 has aces.
Dealing pairs routine Quote
12-26-2017 , 10:25 PM
Are you looking for a simulation? Like the function performs 1 random draw and tells you what the outcome was? Because I think it's not too hard to analytically arrive at the distributions of outcomes, but that doesn't sound like what you want.

I don't know VB but I could probably do it in python, C++ or java.
Dealing pairs routine Quote
12-27-2017 , 12:28 AM
Yes, it is for a simulation program. You can easily do it analytically for 1 opponent, and easily approximate it for n>1 but I’m not sure an exact solution for more than 1 opponent is easy.

Anyway, I did develop a routine I think is correct. It involves a dynamically changing vector that relates a random number to a dealt pair. The vector changes as pairs are dealt. I thought a more elegant solution might be available, but since this was for some research I am doing, elegance is not a priority. If you do come up with a python approach, I can probably translate it into VBA.
Dealing pairs routine Quote
12-27-2017 , 02:37 PM
For the 5 person game, there are only 26 choose 5 ways to deal the pairs (65,780) - simple enumeration seems like it would work well. I'll take a pass at that.
Dealing pairs routine Quote
12-27-2017 , 03:20 PM
Actually when I started writing this I realized it is actually not too hard to calculate. First, instead of thinking of it as 6 cards, and you choose 2 and then there are 2 left to make another pair, think of it as a list of numbers from 0 to 26. 0 and 1 and the first pairs, 2 and 3 are the 2nd pairs, and so forth, making 13 pairs.

For a 5 person game, the counts can be
A A / B B / C
A A / B / C / D
A / B / C / D / E
There aren't any other ways it could go.

There are 26c5 total outcomes, so we can count the ways to do particular outcomes to find the probability. For example, the chance for a specific AABBC match, like say
2 pairs of 5s, 2 pairs of 6s, 1 pair of 7s
is 2 / 26c5. This is because we have to draw both of the 5 and 6 pairs, but we get to choose "which" 7 pair we get.

If we want to know the chance of being in a AABBC situation that involves 5, 6 and 7, then that's 6/26c5 because there are 6 ways to arrange A B and C, but AABB is the same as BBAA so there are 3 unique ways

If we want to know the chance that it'll be a AABBC situation in general, then, it's
13c3 * 6 / 26c5 = 286*6 / 65780 = 1716/65780

The other ones yield to similar analysis. For AABCD types, you have
8 ways to make any specific one (because there are 2 choices for B C and D, 2*2*2=8)

There are 32 ways to make an AABCD type that uses, say, 5 6 7 and 8, because although there are 4! ways to arrange the letters, all the combos of BCD are the same, so it's 4!/3!.

So there are 32*13c4 ways to make all AABCD types.

For the ABCDE types, you have 32 ways to pick any particular set of pairs, because each pair has 2 ways and there are 5 of them, 2^5 = 32. So there are 32*13c5 ways to make ABCDE types.

For any "type" the formula is fairly simple, the only thing you have to do manually is figure out which "types" are available given the number of players. The formula is
2^S*RcD*13cR
where
S is the number of single pairs
D is the number of double pairs
R is the number of distinct ranks
I *think* this is right
Dealing pairs routine Quote
12-27-2017 , 03:26 PM
I think each player is only dealt 2 cards and it's guaranteed to be a pair.
Dealing pairs routine Quote
12-27-2017 , 04:46 PM
I just got back to this.
Thanks for the response Rusty, I will look at it carefully and get back to you. Lattimer’s comment is correct and I think your analysis assumes this.

Actually, the problem I’m dealing with is actually a little more complex. It assumes hero has a set of known rank, so we know hero has a pair and one flop card gives him a set. I’m then interested in the probability of hero losing to a higher set or quads, recognizing hero can also get quads. But, if the thread problem I posed can be analytically solved, it shouldn’t be too hard to modify.
Dealing pairs routine Quote
12-27-2017 , 05:12 PM
Yeah I know they're guaranteed to get a pair. That's why I said you could just make a "deck" out of 26 items, each item representing a pair.

But that's really very different than your OP. Neither the code nor the analysis are that similar, I think.
Dealing pairs routine Quote
12-27-2017 , 06:39 PM
With a fairly quick check, Rusty's approach looks good. Summing his probs for the example gives a total prob of 100%, as it should. I'll now try to modify it to attack the overset problem I'm addressing.

Thanks for your responses guys.
Dealing pairs routine Quote
12-27-2017 , 07:43 PM
BTW because the sample size is small, attacking it enumeratively, instead of doing the math, is very feasible. In python, it's actually quite easy, because python has a function that makes all combinations possible from a list. Here's an example:

Code:
#!/usr/bin/env python

from collections import defaultdict
import itertools

sizes = defaultdict(int)
count = 0
for i in itertools.combinations(range(26), 5):
    count += 1
    foo = defaultdict(int)
    for el in i:
        foo[el/2] += 1

    sizes[len(foo)] += 1

print count, sizes
Code:
(otx) lolbutts:~/Code/labs-pulse $ ./pairs2.py
65780 defaultdict(<type 'int'>, {3: 1716, 4: 22880, 5: 41184})
Dealing pairs routine Quote
12-27-2017 , 07:46 PM
I should say, the reason I'm counting and printing the sizes is that "foo" contains the pairs in this set and how many of each there are. So for example it'll be something like
{2: 1, 5: 1, 7: 1, 10: 2}
meaning 1 pair of 2s, 1 pair of 5s, 1 pair of 7s and 2 pairs of 10s. The length of this dict is 4. Any dict that has a length of 4 must be 3 individual pairs and 1 double-pair.

len(3) = double double single
len(4) = DSSS
len(5) = SSSSS
Dealing pairs routine Quote
12-28-2017 , 01:08 PM
I’m having second thoughts about Rusty’s initial structure. He postulated 26 pairs, 2 for each for the 13 ranks. For two players, by his method, the probability of two different pairs (AB) equals 96% vs 4% for two same rank pairs (AA). You can get these results by straightforward calculation, e.g.,

P(2 pairs of same rank | 26 possible pairs) = 13*(2/26)*(1/25) = 1/25 = 4%.

In the OP, I postulated each rank had 6 possible pairs, leading to a total of 78. If we use 78 possible pairs as the initial structure,

P(2 pairs of same rank|78 possible pairs) = 13*(6/78)*(1/73) = 1.4%,

a significant difference from Rusty’s result.

So, while his calculation algorithm is nice, I think the basic assumption of 26 pairs is not supportable.
Dealing pairs routine Quote
12-28-2017 , 02:11 PM
Quote:
Originally Posted by RustyBrooks
Yeah I know they're guaranteed to get a pair. That's why I said you could just make a "deck" out of 26 items, each item representing a pair.

But that's really very different than your OP. Neither the code nor the analysis are that similar, I think.
I very quickly glanced at your analysis and assumed you were using 5-card hands based on the ABCDE, that's why I made my post. It was an unfortunate coincidence you were giving a 5 player example.
Dealing pairs routine Quote
12-28-2017 , 04:42 PM
Yeah, I think you're right, my model doesn't match reality.

I wrote another program, this one takes a normal holdem deck, and deals out every possible pair of holdem hands. If both hands aren't pairs, it throws them out. If they are, it counts them and checks if they're the same pair. It gets the same number as you - 1.36986%

Code:
#!/usr/bin/env python

from collections import defaultdict
import itertools

count = 0
match = 0
deck = [
    '2c', '2h', '2s', '2d',
    '3c', '3h', '3s', '3d',
    '4c', '4h', '4s', '4d',
    '5c', '5h', '5s', '5d',
    '6c', '6h', '6s', '6d',
    '7c', '7h', '7s', '7d',
    '8c', '8h', '8s', '8d',
    '9c', '9h', '9s', '9d',
    'Tc', 'Th', 'Ts', 'Td',
    'Jc', 'Jh', 'Js', 'Jd',
    'Qc', 'Qh', 'Qs', 'Qd',
    'Kc', 'Kh', 'Ks', 'Kd',
    'Ac', 'Ah', 'As', 'Ad',
]

for i in itertools.permutations(deck, 4):
    if i[0][0] != i[1][0] or i[2][0] != i[3][0]:
        continue

    count += 1
    if i[0][0] == i[2][0]:
        match += 1

print match, count, 100.0*match/count
Dealing pairs routine Quote
04-06-2018 , 05:46 PM
Quote:
Originally Posted by statmanhal
P(2 pairs of same rank|78 possible pairs) = 13*(6/78)*(1/73) = 1.4%
I like your approach! Here's another.

N(AB) = C(13,2) * C(4,2)^2
N(AA) = 13 * 3

P(AA) = 39 / 2847 = 1.36986301%

For N(AA) you multiply by 3 because all 3 ways to distribute the cards among the two players are valid (in that they all result in the players having pairs). For N(AB) there is only one valid distribution (since I'm treating the players as unlabeled).

For the 5-player case:

N(ABCDE) = C(13,5) * 6^5 = 10007712
N(AABCD) = 4*C(13,4) * 6^3 * 3 = 1853280
N(AABBC) = 3*C(13,3) * 6 * 3^2 = 46332
Total = 11907324

Again the magenta terms are the ways to distribute the cards.
Dealing pairs routine Quote

      
m