The first step would be to find the number of choices. In this case, we would use a combination rather than a permutation, since the order of our choices is irrelevant. We can find this number with:
sub choose {
my ($n, $k) = @_;
my ($result, $j) = (1, 1);
return 0 if $k > $n || $k < 0;
$k = ($n - $k) if ($n - $k) < $k;
while ( $j <= $k ) {
$result *= $n--;
$result /= $j++;
}
return $result;
}
my $people = 48;
my $teams = 8;
my $seasons = 3;
print choose($people, ($people/$teams));
In your case, there are a possible 12271512 different team combinations, but this isn't the complete answer yet. You'll actually want to generate these teams such that you can find which of them have repeated couples.
I've got some coding for work to do, but I'll crunch on this throughout the day and update as I can, barring someone else having more freetime and posting a solution before I do.
C-.
Update: Or you could completely ignore my intellectually overstimulated response and go with what Abigail-II suggested, which will actually solve the problem. Thanks for the instruction.
---
Flex the Geek |