logo       

[SPOILER]match of the week solution: msg#00015

lang.perl.qotw.discuss

Subject: [SPOILER]match of the week solution



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



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise