Round Robin Tournament
This little ruby gem implements the Round Robin Tournament scheduling. It is useful when you want a competition
"in which each contestant meets all other contestants in turn", or if you have a classroom
of students and want them to work in pairs, but with a different partner every day.
Upgrade
If you upgrade from version 0.0.1
to 0.1.2
, the tournament rotation has been reversed, which brings stability on first day pairs for a growing number for participants.
Installation
Add this line to your application's Gemfile:
gem 'round_robin_tournament'
And then execute:
$ bundle
Usage
Call the method RoundRobinTournament.schedule
with one argument,
an Array
of size n
. It will return an array of n - 1
elements,
the days, and each element is an array of two elements, the game competitors.
If n
is off, then the first element of each array element will be
an array of two element, the last one being nil
.
Example (n
is even)
require "round_robin_tournament"
students = %w(John Paul Ringo George)
teams = RoundRobinTournament.schedule(students)
teams.each_with_index do |day, index|
day_teams = day.map { |team| "(#{team.first}, #{team.last})" }.join(", ")
puts "Day #{index + 1}: #{day_teams}"
end
Example (n
is odd)
require "round_robin_tournament"
students = %w(John Paul Ringo George OtherGuy)
teams = RoundRobinTournament.schedule(students)
teams.each_with_index do |day, index|
day_teams = day.map { |team| "(#{team.first}, #{team.last})" }.join(", ")
puts "Day #{index + 1}: #{day_teams}"
end
Credits
I'd like to thank Pierre-Olivier Goffard,
Joel Cohen and Florent Rovetta from the Institut de Mathématiques de Marseille who helped a lot!