[SPOILER]match of the week solution
"Tor Fuglerud" <[email protected]> Tue, 18 Jan 2005 09:30:41 +0100
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Organization | UiO |
| Message-ID | <[email protected]> |
Not entierly to spec :-) but here's a fairly short RR alocation routine
using a circle methaphor.
a a a
d b -> c d -> b c
c b d
place all the teams around a circle, keep the one at 12 oclock fixed and
rotate the rest. Pair off oposing teams.
(you obiously need an even number of teams so / ("no team") is added if
odd number)
#!/local/bin/perl5 -w
use strict;
my @teams = qw(A B C D E F);
my @list;
push @teams, '/' if @teams % 2;
for my $round (0 .. @teams-2) {
push @teams, splice @teams, 1, 1;
@{$list[$round]} = map "$teams[$_]-$teams[@teams-$_-1]", (0 .. @teams
/ 2 - 1);
}
for (@list){print "@$_\n"};
--
Tor Fuglerud