Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Round robin tournament problem

by Limbic~Region (Chancellor)
on Oct 21, 2003 at 23:40 UTC ( #301110=note: print w/replies, xml ) Need Help??

in reply to Round robin tournament problem

I only see an easy solution for for 2n players. I have provided working brute-force code for those cases.
#!/usr/bin/perl -w use strict; my @name = qw(a b c d e f g h); die "You must have an even number of players" if @name % 2; my %tournament; $tournament{$_} = [] for @name; for my $round (1 .. $#name) { $round--; for my $player (@name) { next if $tournament{$player}->[$round]; for my $opponent (@name) { next if $opponent eq $player; next if $tournament{$opponent}->[$round]; next if @{$tournament{$player}} && grep /^$opponent$/ , @{ +$tournament{$player}}; $tournament{$player}->[$round] = $opponent; $tournament{$opponent}->[$round] = $player; last; } } } for my $round (1 .. $#name) { $round--; print "\n\nRound: $round\n"; my %seen; for my $player (@name) { next if $seen{$player}; print "$player plays $tournament{$player}->[$round]\n"; $seen{$tournament{$player}->[$round]} = 1; } }
Update: Originally, I stated that this was all that's possible, but as blokhead points out non 2n solutions with backtracking is possible.

Hope this gets you started - L~R

Replies are listed 'Best First'.
Re: Re: Round robin tournament problem
by waswas-fng (Curate) on Oct 21, 2003 at 23:56 UTC
    It is possible just not a ballanced table, you will have a table like the following:
    Round 1 A-B C-D E Sits Out Round 2 B-C D-E A Sits Out ...


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://301110]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2021-03-04 16:04 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (105 votes). Check out past polls.