Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

round_robin_tournament

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

round_robin_tournament

  • 0.1.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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.

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"

# 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!

FAQs

Package last updated on 28 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc