|
[SPOILER] My solution to the tournament scheduler quiz: msg#00020lang.perl.qotw.discuss
I just coded up the algorithm given at http://www.gamecabinet.com/rules/RoundRobinScheme.html Walt ----------------- #!/usr/local/bin/perl -w use strict; my $sched = allocate_schedule($ARGV[0]); print_sched($sched); sub allocate_schedule { my $n = shift; $n++ if $n % 2; # add ghost player my @teams = (0..$n-1); my @sched; for (1..$n-1) { my @round; for my $j (0..$n-1) { $round[$teams[$j]] = $teams[-($j+1)]; } push @sched, \@round; unshift @teams, splice @teams, -2, 1; } return \@sched; } sub print_sched { my $sched = shift; my $out = "["; for my $round (@$sched) { $out .= "[" . join(",", @$round) . '],'; } chop $out; # remove final , $out .= "]"; print "$out\n"; }
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Perl Translation: 00020, Shlomi Fish |
|---|---|
| Next by Date: | Re: [SPOILER] Medium QOTW 1 solution: 00020, Shlomi Fish |
| Previous by Thread: | [SPOILER]match of the week solutioni: 00020, Tor Fuglerud |
| Next by Thread: | Easy/Expert quizzes: 00020, Bill Smith |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |