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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.