Giter VIP home page Giter VIP logo

round_robin_tournament's Introduction

Build Status Gem Version

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.

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"

# Compute all the possible teams for each day in the classroom
students = %w(John Paul Ringo George)
teams = RoundRobinTournament.schedule(students)

# Print for each day, each team
teams.each_with_index do |day, index|
  day_teams = day.map { |team| "(#{team.first}, #{team.last})" }.join(", ")
  puts "Day #{index + 1}: #{day_teams}"
end

# Day 1: (Paul, George), (Ringo, John)
# Day 2: (Ringo, George), (John, Paul)
# Day 3: (John, George), (Paul, Ringo)

Example (n is odd)

require "round_robin_tournament"

# Compute all the possible teams for each day in the classroom
students = %w(John Paul Ringo George OtherGuy)
teams = RoundRobinTournament.schedule(students)

# Print for each day, each team
teams.each_with_index do |day, index|
  day_teams = day.map { |team| "(#{team.first}, #{team.last})" }.join(", ")
  puts "Day #{index + 1}: #{day_teams}"
end

# Day 1: (Paul, ), (Ringo, John), (George, OtherGuy)
# Day 2: (Ringo, ), (George, Paul), (OtherGuy, John)
# Day 3: (George, ), (OtherGuy, Ringo), (John, Paul)
# Day 4: (OtherGuy, ), (John, George), (Paul, Ringo)
# Day 5: (John, ), (Paul, OtherGuy), (Ringo, George)

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!

round_robin_tournament's People

Contributors

ssaunier avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.