double_round_robin_schedule 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +11 -0
- data/double_round_robin_schedule.gemspec +25 -0
- data/lib/double_round_robin_schedule.rb +48 -0
- data/lib/double_round_robin_schedule/version.rb +3 -0
- data/test/test_double_round_robin_schedule.rb +11 -0
- data/test/test_helper.rb +4 -0
- metadata +98 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 71d9ddd4ca21bcb2e106084b96443cae8ea132a0
|
|
4
|
+
data.tar.gz: c5c31ac69bb322a78baec9319d505ed84cfb2d1c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d5b2fa0e540d6c26c895cfa172a30dfab7ab89c3ebd6d2c5d59ad46adc94804e7c52481e91b8e9885d323afa65d8ba046df33affe69448bf620d4ef6788e8924
|
|
7
|
+
data.tar.gz: f5d265bd146fc7bb9bb64eac10b55065341a01daeed04f941f4911d3fdc1ca81f514b70dc92f5853a132ae916869cee446957f497cdad881fe0426b09f44a3d0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 TODO: Write your name
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[](http://badge.fury.io/rb/double_round_robin_schedule)
|
|
2
|
+
[](https://travis-ci.org/nithinstany/double_round_robin_schedule)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Round Robin Tournament
|
|
6
|
+
|
|
7
|
+
This little ruby gem implements the [Round Robin Tournament](http://en.wikipedia.org/wiki/Round-robin_tournament#Scheduling_algorithm) 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.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
|
|
13
|
+
gem 'double_round_robin_schedule'
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install double_round_robin_schedule
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
require "double_round_robin_schedule"
|
|
27
|
+
|
|
28
|
+
# Compute all the possible teams for each day in the classroom
|
|
29
|
+
playing_teams = %w(team1 team2 team3 team4)
|
|
30
|
+
matches = DoubleRoundRobinSchedule.schedule(playing_teams)
|
|
31
|
+
|
|
32
|
+
# Print for each day, each team
|
|
33
|
+
matches.each_with_index do |day, index|
|
|
34
|
+
day_teams = day.map { |team| "(#{team.first}, #{team.last})" }.join(", ")
|
|
35
|
+
puts "Day #{index + 1}: #{day_teams}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Day 1: (team2, team4), (team3, team1)
|
|
39
|
+
# Day 2: (team3, team4), (team1, team2)
|
|
40
|
+
# Day 3: (team1, team4), (team2, team3)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Contributing
|
|
44
|
+
|
|
45
|
+
1. Fork it ( http://github.com/nithinstany/double_round_robin_schedule/fork )
|
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'double_round_robin_schedule/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "double_round_robin_schedule"
|
|
8
|
+
spec.version = DoubleRoundRobinSchedule::VERSION
|
|
9
|
+
spec.authors = ["nithin stany dsouza"]
|
|
10
|
+
spec.email = ["nithinstany@gmail.com"]
|
|
11
|
+
spec.summary = %q{Round Robin Tournament schedule for competitions or classroom teams}
|
|
12
|
+
spec.description = spec.summary
|
|
13
|
+
spec.homepage = "https://github.com/nithinstany/double_round_robin_schedule"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
spec.add_development_dependency 'minitest'
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require "double_round_robin_schedule/version"
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
|
|
4
|
+
module DoubleRoundRobinSchedule
|
|
5
|
+
|
|
6
|
+
def self.schedule(all_teams)
|
|
7
|
+
numweeks = (all_teams.length - 1) * 2
|
|
8
|
+
halfsize = all_teams.length / 2
|
|
9
|
+
|
|
10
|
+
teams = all_teams.dup
|
|
11
|
+
temp = all_teams.dup
|
|
12
|
+
teams.shift
|
|
13
|
+
team_size = teams.length
|
|
14
|
+
week = 0
|
|
15
|
+
games = []
|
|
16
|
+
|
|
17
|
+
while( week < numweeks) do
|
|
18
|
+
week_matches = []
|
|
19
|
+
if (week % 2 == 0)
|
|
20
|
+
teamIdx = week % team_size
|
|
21
|
+
week_matches << [teams[teamIdx], temp[0] ]
|
|
22
|
+
idx = 0
|
|
23
|
+
while( idx < halfsize) do
|
|
24
|
+
firstTeam = (week + idx) % team_size
|
|
25
|
+
secondTeam = ((week + team_size) - idx) % team_size
|
|
26
|
+
week_matches << [teams[firstTeam], teams[secondTeam] ] if (firstTeam != secondTeam)
|
|
27
|
+
idx = idx + 1
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if (week % 2 != 0)
|
|
32
|
+
teamIdx = week % team_size
|
|
33
|
+
week_matches << [temp[0] , teams[teamIdx]]
|
|
34
|
+
idx = 0
|
|
35
|
+
while( idx < halfsize) do
|
|
36
|
+
firstTeam = (week + idx) % team_size
|
|
37
|
+
secondTeam = ((week + team_size) - idx) % team_size
|
|
38
|
+
week_matches << [teams[secondTeam], teams[firstTeam]] if (firstTeam != secondTeam)
|
|
39
|
+
idx = idx + 1
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
games[week] ||= []
|
|
43
|
+
games[week] += week_matches
|
|
44
|
+
week = week + 1
|
|
45
|
+
end
|
|
46
|
+
games
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
require File.expand_path('../test_helper.rb', __FILE__)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestDoubleRoundRobinSchedule < MiniTest::Unit::TestCase
|
|
6
|
+
def test_double_round_robin_schedule
|
|
7
|
+
assert_equal(DoubleRoundRobinSchedule.schedule(['team1', 'team2', 'team3', 'team4']), [[["team2", "team1"], ["team3", "team4"]], [["team1", "team3"], ["team2", "team4"]], [["team4", "team1"], ["team2", "team3"]], [["team1", "team2"], ["team4", "team3"]], [["team3", "team1"], ["team4", "team2"]], [["team1", "team4"], ["team3", "team2"]]])
|
|
8
|
+
assert_equal(DoubleRoundRobinSchedule.schedule(['team1', 'team2', 'team3']), [[["team2", "team1"]], [["team1", "team3"]], [["team2", "team1"]], [["team1", "team3"]]])
|
|
9
|
+
assert_equal(DoubleRoundRobinSchedule.schedule(['team1', 'team2']), [[["team2", "team1"]], [["team1", "team2"]]] )
|
|
10
|
+
end
|
|
11
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: double_round_robin_schedule
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- nithin stany dsouza
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.5'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.5'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: Round Robin Tournament schedule for competitions or classroom teams
|
|
56
|
+
email:
|
|
57
|
+
- nithinstany@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- Gemfile
|
|
64
|
+
- LICENSE.txt
|
|
65
|
+
- README.md
|
|
66
|
+
- Rakefile
|
|
67
|
+
- double_round_robin_schedule.gemspec
|
|
68
|
+
- lib/double_round_robin_schedule.rb
|
|
69
|
+
- lib/double_round_robin_schedule/version.rb
|
|
70
|
+
- test/test_double_round_robin_schedule.rb
|
|
71
|
+
- test/test_helper.rb
|
|
72
|
+
homepage: https://github.com/nithinstany/double_round_robin_schedule
|
|
73
|
+
licenses:
|
|
74
|
+
- MIT
|
|
75
|
+
metadata: {}
|
|
76
|
+
post_install_message:
|
|
77
|
+
rdoc_options: []
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
requirements: []
|
|
91
|
+
rubyforge_project:
|
|
92
|
+
rubygems_version: 2.2.2
|
|
93
|
+
signing_key:
|
|
94
|
+
specification_version: 4
|
|
95
|
+
summary: Round Robin Tournament schedule for competitions or classroom teams
|
|
96
|
+
test_files:
|
|
97
|
+
- test/test_double_round_robin_schedule.rb
|
|
98
|
+
- test/test_helper.rb
|