UPDATE: My original question was overly complex. I'm re-phrasing it, removing the repeated part of the question, and focusing just on the combinations.
I organize a group of players. The group is mixed, and there are 4 courts. There are 8 men and 8 women.
Here is my approach, and where I get a bit confused.
Start with the men or women, "genderA" On court 1, we need to opponents, no repetition, order matters.
$\binom{8}{2} = 28$
One court 2, we pick the next pairing
$\binom{6}{2} = 15$
Then Court 3
$\binom{4}{2} = 6$
And the last 2 players go to court 4. Only one remaining combination
From the above, I calculate there are 28*15*6 possible orderings of genderA, or 2560 solutions.
When choosing genderB, order DOES matter. Starting on court 1, we pick partners, and here we have P(8,2) = 56
Court 2 we have P(6,2) = 30 Court 3 is P(4,2) = 12 Court 4 is P(2,2) = 2
Or 56*30*12*2 = 40,320 combinations.
Now, I need to combine the combinations of genderA and genderB. If I re-calculate this, maybe that works better? (some confusion here)
What if I calculate the combinations for court 1 for both genders?
$\binom{8}{2} * ^{8}P_{2} = 28*56 = 1568$
Court 2: $\binom{6}{2} * ^{6}P_{2} = 15*30 = 450$
Court 3: $\binom{4}{2} * ^{4}P_{2} = 12*6 = 72 $
Court 3: $\binom{2}{2} * ^{2}P_{2} = 2*1 = 2 $
My final answer would then be (???) 1568*450*72*2 = 101,606,400
That seems quite high, but also seems correct. If this is correct then the 4th court adds MANY more combinations than having 3 courts only. 100M versus 64K!
I would appreciate someone checking my math here, as I can't help feeling I've made some fundamental error in all of this.
Cheers,
Ed
To compute the number of combinations you have, the first man can go anywhere. You then have $7$ choices for the man to oppose him. The third man can go anywhere left and you have $5$ left to oppose him. The third pairing gives another factor $3$, so there are $7\cdot 5 \cdot 3=105$ ways to distribute the men. Then the locations for the women are all distinct, so there are $8!=40320$ ways to distribute the women, for $105 \cdot 40320=4\ 233\ 600$ total. This assumes that the courts are identical. That is few enough that you can run through them all looking for the optimum.
Three loops will get you the list of possibilities for the men. If you search for generate permutations you find Heap's algorithm is well regarded. You can use that for the permutation of the women. I believe one of the Python packages has a function that generates all the permutations for you so you don't have to roll your own.