slsp-circlemethod 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.ja.md +98 -0
- data/README.md +95 -0
- data/Rakefile +12 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/lib/slsp/circlemethod/version.rb +7 -0
- data/lib/slsp/circlemethod.rb +230 -0
- data/sig/slsp/circlemethod.rbs +9 -0
- data/slsp-circlemethod.gemspec +30 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ca4990c304c5d53044e494f9267067e2fd73e4ec73603e61a030cb38991eea14
|
4
|
+
data.tar.gz: 475064d40fd2b57cf5a6834cbcddcf9730abd3847d854272c465b7f251cda6e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7aa99e782c91e9f3001c57dfd3fd2ce0e41c27a09263ad9c1bb1ed40c7326d0d0731463f7838e79911ac213ae9360860800e7f0377efdb8d1ecb279819f7016
|
7
|
+
data.tar.gz: 5356bb63266610577d0c3ecf647ee6b300a39977dbf62a93844a6026e8ff4e0deedc538c85f5a3b6e999e250e060f0c14a1e44f396157c66dcdd0c106ddc52b9
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
|
9
|
+
## [Unreleased]
|
10
|
+
|
11
|
+
|
12
|
+
## [1.0.0] - 2022-01-14
|
13
|
+
|
14
|
+
- Initial release
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Implement CircleMethod.each()
|
18
|
+
- Implement CircleMethod.each_with_fair_break()
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Joji Wakairo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.ja.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# SLSP::CircleMethod
|
2
|
+
|
3
|
+
[![Ruby](https://github.com/wakairo/slsp-circlemethod/actions/workflows/main.yml/badge.svg)](https://github.com/wakairo/slsp-circlemethod/actions/workflows/main.yml)
|
4
|
+
|
5
|
+
SLSP:: CircleMethodは、スポーツスケジューリング問題におけるcircle methodを用いたメソッドを提供します。
|
6
|
+
|
7
|
+
## インストール
|
8
|
+
|
9
|
+
このgemを利用するアプリケーションのGemfileに以下の行を追加して下さい。
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'slsp-circlemethod'
|
13
|
+
```
|
14
|
+
|
15
|
+
そして、以下のコマンドを実行して下さい。
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
もし以上のようにGemfileを利用しないのであれば、以下のコマンドでインストールして下さい。
|
20
|
+
|
21
|
+
$ gem install slsp-circlemethod
|
22
|
+
|
23
|
+
## 利用方法
|
24
|
+
|
25
|
+
### each()
|
26
|
+
|
27
|
+
SLSP::CircleMethod.each()は、Circle methodを利用することで、同時に行われる試合の集まり、つまり、ラウンドを考慮した上で、nチームの対戦スケジュールを計算します。
|
28
|
+
|
29
|
+
コード例:
|
30
|
+
```ruby
|
31
|
+
teams = %w(A B C D E F G H)
|
32
|
+
enum = SLSP::CircleMethod.each_with_fair_break(teams.size)
|
33
|
+
enum.each_slice(teams.size/2).each_with_index do |x, i|
|
34
|
+
puts "Round #{i}: " + x.map{|p,q| "#{teams[p]} vs #{teams[q]}"}.join(", ")
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
出力:
|
39
|
+
```
|
40
|
+
Round 0: A vs H, G vs B, C vs F, E vs D
|
41
|
+
Round 1: B vs H, A vs C, D vs G, F vs E
|
42
|
+
Round 2: H vs C, B vs D, E vs A, G vs F
|
43
|
+
Round 3: D vs H, C vs E, F vs B, A vs G
|
44
|
+
Round 4: H vs E, D vs F, G vs C, B vs A
|
45
|
+
Round 5: F vs H, E vs G, A vs D, C vs B
|
46
|
+
Round 6: H vs G, F vs A, B vs E, D vs C
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
### each_with_fair_break()
|
51
|
+
|
52
|
+
SLSP::CircleMethod.each_with_fair_break()は、さらにブレイクを考慮した上で、対戦スケジュールを計算します。
|
53
|
+
スポーツスケジューリング問題では、ブレイクは「2回連続したホーム・ゲームまたはアウェイ・ゲーム」のことを意味します。
|
54
|
+
以下の例では、AとB、D、Fの4チームが「hh」(2回連続したホーム・ゲーム)を持ち、CとE、G、Hの4チームが「aa」(2回連続したアウェイ・ゲーム)を持ちます。
|
55
|
+
したがって、各チームが平等にブレイクを1つずつ持ちます。
|
56
|
+
|
57
|
+
コード例:
|
58
|
+
```ruby
|
59
|
+
teams = %w(A B C D E F G H)
|
60
|
+
puts "Team : " + teams.join(" ")
|
61
|
+
enum = SLSP::CircleMethod.each_with_fair_break(teams.size)
|
62
|
+
enum.each_slice(teams.size/2).each_with_index do |round, i|
|
63
|
+
a = []
|
64
|
+
round.each do |home, away|
|
65
|
+
a[home] = "h"
|
66
|
+
a[away] = "a"
|
67
|
+
end
|
68
|
+
puts "Round #{i}: " + a.join(" ")
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
出力:
|
73
|
+
```
|
74
|
+
Team : A B C D E F G H
|
75
|
+
Round 0: h a h a h a h a
|
76
|
+
Round 1: h h a h a h a a
|
77
|
+
Round 2: a h a a h a h h
|
78
|
+
Round 3: h a h h a h a a
|
79
|
+
Round 4: a h a h a a h h
|
80
|
+
Round 5: h a h a h h a a
|
81
|
+
Round 6: a h a h a h a h
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
## 開発
|
86
|
+
|
87
|
+
このレポジトリをチェックアウトした後に、まず`bin/setup`を実行して下さい。そして次にテストを走らせるために`rake test`を実行して下さい。
|
88
|
+
|
89
|
+
このgemをローカル環境にインストールするには、`bundle exec rake install`を実行して下さい。新たなバージョンをリリースするには、`version.rb`内のバージョン番号を更新してから、`bundle exec rake release`を実行して下さい。このコマンドは、新バージョンに対するgitタグを生成し、このタグとgitコミットをpushし、`.gem`ファイルを[rubygems.org](https://rubygems.org)へpushします。
|
90
|
+
|
91
|
+
## 開発への参加
|
92
|
+
|
93
|
+
バグレポートとプルリクエストはGitHubへお寄せ下さい。
|
94
|
+
https://github.com/wakairo/slsp-circlemethod
|
95
|
+
|
96
|
+
## ライセンス
|
97
|
+
|
98
|
+
このgemは[MIT License](https://opensource.org/licenses/MIT)の下で、オープンソースのライブラリとしてご利用可能です。
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# SLSP::CircleMethod
|
2
|
+
|
3
|
+
[![Ruby](https://github.com/wakairo/slsp-circlemethod/actions/workflows/main.yml/badge.svg)](https://github.com/wakairo/slsp-circlemethod/actions/workflows/main.yml)
|
4
|
+
|
5
|
+
SLSP:: CircleMethod provides methods using the circle method for Sports League Scheduling Problems.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'slsp-circlemethod'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install slsp-circlemethod
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### each()
|
26
|
+
|
27
|
+
By using the circle method, SLSP::CircleMethod.each() computes schedules of matches of n teams considering rounds.
|
28
|
+
|
29
|
+
Example:
|
30
|
+
```ruby
|
31
|
+
teams = %w(A B C D E F G H)
|
32
|
+
enum = SLSP::CircleMethod.each_with_fair_break(teams.size)
|
33
|
+
enum.each_slice(teams.size/2).each_with_index do |x, i|
|
34
|
+
puts "Round #{i}: " + x.map{|p,q| "#{teams[p]} vs #{teams[q]}"}.join(", ")
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Output:
|
39
|
+
```
|
40
|
+
Round 0: A vs H, G vs B, C vs F, E vs D
|
41
|
+
Round 1: B vs H, A vs C, D vs G, F vs E
|
42
|
+
Round 2: H vs C, B vs D, E vs A, G vs F
|
43
|
+
Round 3: D vs H, C vs E, F vs B, A vs G
|
44
|
+
Round 4: H vs E, D vs F, G vs C, B vs A
|
45
|
+
Round 5: F vs H, E vs G, A vs D, C vs B
|
46
|
+
Round 6: H vs G, F vs A, B vs E, D vs C
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
### each_with_fair_break()
|
51
|
+
|
52
|
+
SLSP::CircleMethod.each_with_fair_break() computes the schedules also considering breaks. In Sports League Scheduling Problems, the break means "two consecutive home matches or two consecutive away matches".
|
53
|
+
In the following example, team A, B, D, and F have "hh" (consecutive two home matches), and team C, E, G, and H have "aa" (consecutive two away matches). So, each team has one break fairly.
|
54
|
+
|
55
|
+
Example:
|
56
|
+
```ruby
|
57
|
+
teams = %w(A B C D E F G H)
|
58
|
+
puts "Team : " + teams.join(" ")
|
59
|
+
enum = SLSP::CircleMethod.each_with_fair_break(teams.size)
|
60
|
+
enum.each_slice(teams.size/2).each_with_index do |round, i|
|
61
|
+
a = []
|
62
|
+
round.each do |home, away|
|
63
|
+
a[home] = "h"
|
64
|
+
a[away] = "a"
|
65
|
+
end
|
66
|
+
puts "Round #{i}: " + a.join(" ")
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
Output:
|
71
|
+
```
|
72
|
+
Team : A B C D E F G H
|
73
|
+
Round 0: h a h a h a h a
|
74
|
+
Round 1: h h a h a h a a
|
75
|
+
Round 2: a h a a h a h h
|
76
|
+
Round 3: h a h h a h a a
|
77
|
+
Round 4: a h a h a a h h
|
78
|
+
Round 5: h a h a h h a a
|
79
|
+
Round 6: a h a h a h a h
|
80
|
+
```
|
81
|
+
|
82
|
+
|
83
|
+
## Development
|
84
|
+
|
85
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
|
86
|
+
|
87
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wakairo/slsp-circlemethod.
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
require_relative "circlemethod/version"
|
2
|
+
|
3
|
+
# The SLSP module defines methods for Sports League Scheduling Problems
|
4
|
+
module SLSP
|
5
|
+
# The Circlemethod module defines methods using the circle method for Sports League Scheduling Problems
|
6
|
+
module CircleMethod
|
7
|
+
|
8
|
+
module InternalUseOnly # :nodoc: all
|
9
|
+
def self.convert_to_non_negative_int n
|
10
|
+
unless n.respond_to?(:to_int)
|
11
|
+
raise TypeError.new("no implicit conversion of #{n.class} into Integer")
|
12
|
+
end
|
13
|
+
i = n.to_int
|
14
|
+
if i < 0
|
15
|
+
raise RangeError.new("#{n} must be a non-negative value")
|
16
|
+
end
|
17
|
+
i
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.each_of_even(n)
|
21
|
+
n_1 = n-1
|
22
|
+
n_1.times do |i|
|
23
|
+
q = i + 1
|
24
|
+
r = q + n - 3
|
25
|
+
yield [i, n_1]
|
26
|
+
(n/2-1).times do |j|
|
27
|
+
yield [q%n_1, r%n_1]
|
28
|
+
q+=1
|
29
|
+
r-=1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
def self.each_of_odd(n)
|
34
|
+
n.times do |i|
|
35
|
+
q = i + 1
|
36
|
+
r = q + n - 2
|
37
|
+
((n+1)/2-1).times do |j|
|
38
|
+
yield [q%n, r%n]
|
39
|
+
q+=1
|
40
|
+
r-=1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.each_with_fair_break_of_even(n)
|
46
|
+
n_1 = n-1
|
47
|
+
n_1.times do |i|
|
48
|
+
q = i + 1
|
49
|
+
r = q + n - 3
|
50
|
+
yield(
|
51
|
+
if 0==i or i.odd?
|
52
|
+
[i, n_1]
|
53
|
+
else
|
54
|
+
[n_1, i]
|
55
|
+
end
|
56
|
+
)
|
57
|
+
(n/2-1).times do |j|
|
58
|
+
yield(
|
59
|
+
if j.even?
|
60
|
+
[r%n_1, q%n_1]
|
61
|
+
else
|
62
|
+
[q%n_1, r%n_1]
|
63
|
+
end
|
64
|
+
)
|
65
|
+
q+=1
|
66
|
+
r-=1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
def self.each_with_fair_break_of_odd(n)
|
71
|
+
n.times do |i|
|
72
|
+
q = i + 1
|
73
|
+
r = q + n - 2
|
74
|
+
((n+1)/2-1).times do |j|
|
75
|
+
yield(
|
76
|
+
if j.even?
|
77
|
+
[r%n, q%n]
|
78
|
+
else
|
79
|
+
[q%n, r%n]
|
80
|
+
end
|
81
|
+
)
|
82
|
+
q+=1
|
83
|
+
r-=1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# call-seq:
|
90
|
+
# CircleMethod.each(n){|pair| ... } -> nil
|
91
|
+
# CircleMethod.each(n) -> new_enumerator
|
92
|
+
#
|
93
|
+
# Calls the block with pairs of two different integers,
|
94
|
+
# whose correspond to +n+ teams, and
|
95
|
+
# returns +nil+.
|
96
|
+
#
|
97
|
+
# +n+ must be a non-negative integer.
|
98
|
+
#
|
99
|
+
# Example 1:
|
100
|
+
# SLSP::CircleMethod.each(4){|match| p match }
|
101
|
+
# Output:
|
102
|
+
# [0, 3]
|
103
|
+
# [1, 2]
|
104
|
+
# [1, 3]
|
105
|
+
# [2, 0]
|
106
|
+
# [2, 3]
|
107
|
+
# [0, 1]
|
108
|
+
#
|
109
|
+
# Example 2:
|
110
|
+
# teams = %w(A B C D)
|
111
|
+
# SLSP::CircleMethod.each(teams.size){|p,q| puts "#{teams[p]} vs #{teams[q]}" }
|
112
|
+
# Output:
|
113
|
+
# A vs D
|
114
|
+
# B vs C
|
115
|
+
# B vs D
|
116
|
+
# C vs A
|
117
|
+
# C vs D
|
118
|
+
# A vs B
|
119
|
+
#
|
120
|
+
# If no block is given, returns a new Enumerator that will enumerate with the pairs.
|
121
|
+
# Example 3:
|
122
|
+
# teams = %w(A B C D)
|
123
|
+
# enum = SLSP::CircleMethod.each(teams.size) #=> #<Enumerator: SLSP::CircleMethod:each(4)>
|
124
|
+
# enum.each_slice(teams.size/2).each_with_index do |x, i|
|
125
|
+
# puts "Round #{i}: " + x.map{|p,q| "#{teams[p]} vs #{teams[q]}"}.join(", ")
|
126
|
+
# end
|
127
|
+
# Output:
|
128
|
+
# Round 0: A vs D, B vs C
|
129
|
+
# Round 1: B vs D, C vs A
|
130
|
+
# Round 2: C vs D, A vs B
|
131
|
+
#
|
132
|
+
def self.each(n, &block)
|
133
|
+
i = InternalUseOnly.convert_to_non_negative_int(n)
|
134
|
+
unless block_given?
|
135
|
+
return enum_for(__method__, i){ i*(i-1)/2 }
|
136
|
+
end
|
137
|
+
if i.even?
|
138
|
+
InternalUseOnly.each_of_even(i, &block)
|
139
|
+
else
|
140
|
+
InternalUseOnly.each_of_odd(i, &block)
|
141
|
+
end
|
142
|
+
nil
|
143
|
+
end
|
144
|
+
|
145
|
+
# call-seq:
|
146
|
+
# CircleMethod.each_with_fair_break(n){|pair| ... } -> nil
|
147
|
+
# CircleMethod.each_with_fair_break(n) -> new_enumerator
|
148
|
+
#
|
149
|
+
# Calls the block with pairs of two different integers,
|
150
|
+
# whose correspond to +n+ teams,
|
151
|
+
# where all teams have the same number of breaks, and
|
152
|
+
# returns +nil+.
|
153
|
+
#
|
154
|
+
# +n+ must be a non-negative integer.
|
155
|
+
#
|
156
|
+
# About breaks, see the following paragraph.
|
157
|
+
#
|
158
|
+
# Example 1:
|
159
|
+
# SLSP::CircleMethod.each_with_fair_break(8).each_slice(8/2){|round| p round }
|
160
|
+
# Output:
|
161
|
+
# [[0, 7], [6, 1], [2, 5], [4, 3]]
|
162
|
+
# [[1, 7], [0, 2], [3, 6], [5, 4]]
|
163
|
+
# [[7, 2], [1, 3], [4, 0], [6, 5]]
|
164
|
+
# [[3, 7], [2, 4], [5, 1], [0, 6]]
|
165
|
+
# [[7, 4], [3, 5], [6, 2], [1, 0]]
|
166
|
+
# [[5, 7], [4, 6], [0, 3], [2, 1]]
|
167
|
+
# [[7, 6], [5, 0], [1, 4], [3, 2]]
|
168
|
+
#
|
169
|
+
# If no block is given, returns a new Enumerator that will enumerate with the pairs.
|
170
|
+
#
|
171
|
+
# Example 2:
|
172
|
+
# teams = %w(A B C D E F G H)
|
173
|
+
# enum = SLSP::CircleMethod.each_with_fair_break(teams.size)
|
174
|
+
# #=> #<Enumerator: SLSP::CircleMethod:each_with_fair_break(8)>
|
175
|
+
# enum.each_slice(teams.size/2).each_with_index do |x, i|
|
176
|
+
# puts "Round #{i}: " + x.map{|p,q| "#{teams[p]} vs #{teams[q]}"}.join(", ")
|
177
|
+
# end
|
178
|
+
# Output:
|
179
|
+
# Round 0: A vs H, G vs B, C vs F, E vs D
|
180
|
+
# Round 1: B vs H, A vs C, D vs G, F vs E
|
181
|
+
# Round 2: H vs C, B vs D, E vs A, G vs F
|
182
|
+
# Round 3: D vs H, C vs E, F vs B, A vs G
|
183
|
+
# Round 4: H vs E, D vs F, G vs C, B vs A
|
184
|
+
# Round 5: F vs H, E vs G, A vs D, C vs B
|
185
|
+
# Round 6: H vs G, F vs A, B vs E, D vs C
|
186
|
+
#
|
187
|
+
# == Breaks
|
188
|
+
# In Sports League Scheduling Problems, a break means
|
189
|
+
# "two consecutive home matches or two consecutive away matches".
|
190
|
+
# In the following example,
|
191
|
+
# team A, B, D, and F have "hh" (consecutive two home matches), and
|
192
|
+
# team C, E, G, and H have "aa" (consecutive two away matches).
|
193
|
+
# So, each team has one break fairly.
|
194
|
+
#
|
195
|
+
# Example 3:
|
196
|
+
# teams = %w(A B C D E F G H)
|
197
|
+
# puts "Team : " + teams.join(" ")
|
198
|
+
# enum = SLSP::CircleMethod.each_with_fair_break(teams.size)
|
199
|
+
# enum.each_slice(teams.size/2).each_with_index do |round, i|
|
200
|
+
# a = []
|
201
|
+
# round.each do |home, away|
|
202
|
+
# a[home] = "h"
|
203
|
+
# a[away] = "a"
|
204
|
+
# end
|
205
|
+
# puts "Round #{i}: " + a.join(" ")
|
206
|
+
# end
|
207
|
+
# Output:
|
208
|
+
# Team : A B C D E F G H
|
209
|
+
# Round 0: h a h a h a h a
|
210
|
+
# Round 1: h h a h a h a a
|
211
|
+
# Round 2: a h a a h a h h
|
212
|
+
# Round 3: h a h h a h a a
|
213
|
+
# Round 4: a h a h a a h h
|
214
|
+
# Round 5: h a h a h h a a
|
215
|
+
# Round 6: a h a h a h a h
|
216
|
+
#
|
217
|
+
def self.each_with_fair_break(n, &block)
|
218
|
+
i = InternalUseOnly.convert_to_non_negative_int(n)
|
219
|
+
unless block_given?
|
220
|
+
return enum_for(__method__, i){ i*(i-1)/2 }
|
221
|
+
end
|
222
|
+
if i.even?
|
223
|
+
InternalUseOnly.each_with_fair_break_of_even(i, &block)
|
224
|
+
else
|
225
|
+
InternalUseOnly.each_with_fair_break_of_odd(i, &block)
|
226
|
+
end
|
227
|
+
nil
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module SLSP
|
2
|
+
module CircleMethod
|
3
|
+
VERSION: String
|
4
|
+
def self.each: (int n) { ([::Integer, ::Integer]) -> void } -> nil
|
5
|
+
| (int n) -> ::Enumerator[[::Integer, ::Integer], nil]
|
6
|
+
def self.each_with_fair_break: (int n) { ([::Integer, ::Integer]) -> void } -> nil
|
7
|
+
| (int n) -> ::Enumerator[[::Integer, ::Integer], nil]
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/slsp/circlemethod/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "slsp-circlemethod"
|
7
|
+
spec.version = SLSP::CircleMethod::VERSION
|
8
|
+
spec.authors = ["Joji Wakairo"]
|
9
|
+
spec.email = ["jw1@ninegw.sakura.ne.jp"]
|
10
|
+
|
11
|
+
spec.summary = "SLSP:: CircleMethod provides methods using the circle method for Sports League Scheduling Problems."
|
12
|
+
spec.description = "SLSP:: CircleMethod provides methods using the circle method for Sports League Scheduling Problems. By using the circle method, this gem computes schedules of matches of n teams considering rounds and breaks, which are two consecutive home matches or two consecutive away matches."
|
13
|
+
spec.homepage = "https://github.com/wakairo/slsp-circlemethod"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/wakairo/slsp-circlemethod"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/wakairo/slsp-circlemethod/blob/main/CHANGELOG.md"
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
29
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slsp-circlemethod
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joji Wakairo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: test-unit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description: 'SLSP:: CircleMethod provides methods using the circle method for Sports
|
42
|
+
League Scheduling Problems. By using the circle method, this gem computes schedules
|
43
|
+
of matches of n teams considering rounds and breaks, which are two consecutive home
|
44
|
+
matches or two consecutive away matches.'
|
45
|
+
email:
|
46
|
+
- jw1@ninegw.sakura.ne.jp
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- CHANGELOG.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.ja.md
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- lib/slsp/circlemethod.rb
|
60
|
+
- lib/slsp/circlemethod/version.rb
|
61
|
+
- sig/slsp/circlemethod.rbs
|
62
|
+
- slsp-circlemethod.gemspec
|
63
|
+
homepage: https://github.com/wakairo/slsp-circlemethod
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata:
|
67
|
+
homepage_uri: https://github.com/wakairo/slsp-circlemethod
|
68
|
+
source_code_uri: https://github.com/wakairo/slsp-circlemethod
|
69
|
+
changelog_uri: https://github.com/wakairo/slsp-circlemethod/blob/main/CHANGELOG.md
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.5.0
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.0.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: 'SLSP:: CircleMethod provides methods using the circle method for Sports
|
89
|
+
League Scheduling Problems.'
|
90
|
+
test_files: []
|