round_robin_tournament 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/round_robin_tournament.rb +7 -3
- data/lib/round_robin_tournament/version.rb +1 -1
- data/spec/round_robin_tournament_spec.rb +14 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c44c37f2ebf4487b93af39b2ffffea2fd40714f8afdcb563a0abe6d842b6ec26
|
4
|
+
data.tar.gz: 0065134b6fdcf7fab503de34f76217348f2086829cdd3eb0202c85bc7a4f4143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '018d0159564979c31b8ee4b5df4b7b9d98474f55c9bad9bc4e52e5a57002775134df27decc2650c55140133c90f4abb72f6b8fd02178a49aa4b55dd3de4ece73'
|
7
|
+
data.tar.gz: 27b8f68179e0d0d4c614a5420e6c5cc683fc214a309099ed9be57a44464aefb2214926628d8bf1a7fefd790b728e76ec7c3a23d9e33af335ed50fcac65a01fb5
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ of students and want them to work in pairs, but with a different partner every d
|
|
9
9
|
|
10
10
|
## Upgrade
|
11
11
|
|
12
|
-
If you upgrade from version `0.0.1` to `0.1.
|
12
|
+
If you upgrade from version `0.0.1` to `0.1.1`, the tournament rotation has been reversed, which brings **stability** on first day pairs for a growing number for participants.
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
@@ -3,12 +3,16 @@ require 'round_robin_tournament/version'
|
|
3
3
|
module RoundRobinTournament
|
4
4
|
|
5
5
|
def self.schedule(array)
|
6
|
-
array.push
|
6
|
+
array.push(nil) if array.size.odd?
|
7
7
|
n = array.size
|
8
|
-
|
8
|
+
1.step(n / 2, 1).each do |i|
|
9
|
+
array.insert(n - i, array.delete_at(i))
|
10
|
+
end
|
11
|
+
pivot = array.pop
|
9
12
|
games = (n - 1).times.map do
|
13
|
+
day = [[array.first, pivot]] + (1...(n / 2)).map { |j| [array[j], array[n - 1 - j]] }
|
10
14
|
array.rotate!
|
11
|
-
|
15
|
+
day
|
12
16
|
end
|
13
17
|
array.push pivot unless pivot.nil?
|
14
18
|
games
|
@@ -21,18 +21,20 @@ describe RoundRobinTournament do
|
|
21
21
|
expect { check_schedule!(teams) }.not_to raise_error
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
(2..20).to_a.each do |n|
|
25
|
+
it "is stable growing the number of participants from #{n} to #{n + 1}" do
|
26
|
+
day_one = RoundRobinTournament.schedule(("a".."z").to_a.take(n)).first
|
27
|
+
participants_day_two = ("a".."z").to_a.take(n + 1)
|
28
|
+
participants_day_two_last = participants_day_two.last
|
29
|
+
day_two = RoundRobinTournament.schedule(participants_day_two).first
|
30
|
+
|
31
|
+
if n.even?
|
32
|
+
day_two = day_two.reject { |pair| pair.compact.size != 2 }
|
33
|
+
else
|
34
|
+
day_one = day_one.map { |pair| pair.map { |participant| participant.nil? ? participants_day_two_last : participant } }
|
35
|
+
end
|
36
|
+
expect(day_two).to eq(day_one)
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|