Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Round robin tournament problem

by Anonymous Monk
on Oct 22, 2003 at 17:55 UTC ( #301300=note: print w/replies, xml ) Need Help??

in reply to Round robin tournament problem

A visually described algorithm:

Look at how A, B and C follow each other

Round 1
D vs A
B vs C

Round 2
D vs C
A vs B

Round 3
D vs B
C vs A

Visualize the diffence between round 1 and 2 as A went where B was, B went where C was and C went where A was. The same replacement holds when you compare round 2 and 3.

Does not this "cylce" method also work with any even number? I think it does. Yea, I think it does.

If so then for any odd number of teams, add a team called "BYE" and you then have an even number of teams. Any team playing the "BYE" team, um, has a bye.

Example: Teams are A,B,C,D,E,F

Round 1
F v A
B v E
C v D

Round 2
F v E
A v D
B v C

Round 3
F v D
E v C
A v B

Round 4
F v C
D v B
E v A

Round 5
F v B
C v A
D v E

Hope that helps.


Replies are listed 'Best First'.
Re: Re: Round robin tournament problem
by kelan (Deacon) on Oct 22, 2003 at 20:18 UTC

    Here's a function that implements this logic. You pass it the number of players and the round number and it returns a list of numbers. Each pair of numbers is a matchup for that round. (A pair of say 1,4 means "Player 1 plays Player 4".)

    # Function for determining the matchups in a round-robin # tournament round, given the number of players and the # round number. sub matchups { my $players = shift; my $round = shift; # Sanity check the round number if ($round < 1 || $round > $players-1) { return; } my @list = (1, 1+$round .. $players, 2 .. $round); my @pairs; for (0 .. $#list / 2) { push @pairs, $list[$_], $list[$players-1 - $_]; } return @pairs; }
    If there are an odd number of players, the last pair will be the same number twice (meaning "Player 4 plays Player 4"), which is essentially a bye.


    Perl6 Grammar Student

Log In?

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

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

    Results (105 votes). Check out past polls.