combinatorics 0.4.3 → 0.5.0

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.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +28 -0
  3. data/.gitignore +5 -5
  4. data/ChangeLog.md +11 -0
  5. data/Gemfile +16 -0
  6. data/LICENSE.txt +1 -1
  7. data/README.md +144 -107
  8. data/Rakefile +6 -32
  9. data/combinatorics.gemspec +2 -4
  10. data/gemspec.yml +8 -4
  11. data/lib/combinatorics/cartesian_product/cardinality.rb +2 -0
  12. data/lib/combinatorics/cartesian_product/extensions/array.rb +3 -1
  13. data/lib/combinatorics/cartesian_product/extensions/set.rb +3 -1
  14. data/lib/combinatorics/cartesian_product/extensions.rb +4 -2
  15. data/lib/combinatorics/cartesian_product/mixin.rb +3 -1
  16. data/lib/combinatorics/cartesian_product.rb +5 -3
  17. data/lib/combinatorics/choose/cardinality.rb +4 -2
  18. data/lib/combinatorics/choose/extensions/array.rb +3 -1
  19. data/lib/combinatorics/choose/extensions/set.rb +4 -1
  20. data/lib/combinatorics/choose/extensions.rb +4 -2
  21. data/lib/combinatorics/choose/mixin.rb +2 -0
  22. data/lib/combinatorics/choose.rb +5 -3
  23. data/lib/combinatorics/derange/cardinality.rb +3 -1
  24. data/lib/combinatorics/derange/extensions/array.rb +3 -1
  25. data/lib/combinatorics/derange/extensions.rb +3 -1
  26. data/lib/combinatorics/derange/mixin.rb +2 -0
  27. data/lib/combinatorics/derange.rb +5 -3
  28. data/lib/combinatorics/enumerator.rb +2 -0
  29. data/lib/combinatorics/extensions/math.rb +2 -0
  30. data/lib/combinatorics/extensions/range.rb +2 -0
  31. data/lib/combinatorics/extensions.rb +3 -1
  32. data/lib/combinatorics/generator.rb +3 -1
  33. data/lib/combinatorics/list_comprehension.rb +3 -1
  34. data/lib/combinatorics/permute/cardinality.rb +3 -1
  35. data/lib/combinatorics/permute/extensions/array.rb +3 -1
  36. data/lib/combinatorics/permute/extensions/set.rb +3 -1
  37. data/lib/combinatorics/permute/extensions.rb +4 -2
  38. data/lib/combinatorics/permute/mixin.rb +2 -0
  39. data/lib/combinatorics/permute.rb +5 -3
  40. data/lib/combinatorics/power_set/cardinality.rb +3 -1
  41. data/lib/combinatorics/power_set/extensions/array.rb +3 -1
  42. data/lib/combinatorics/power_set/extensions/set.rb +3 -1
  43. data/lib/combinatorics/power_set/extensions.rb +4 -2
  44. data/lib/combinatorics/power_set/mixin.rb +2 -0
  45. data/lib/combinatorics/power_set.rb +5 -3
  46. data/lib/combinatorics/version.rb +3 -1
  47. data/lib/combinatorics.rb +12 -10
  48. data/spec/cartesian_product/cardinality_spec.rb +14 -16
  49. data/spec/cartesian_product/mixin_examples.rb +14 -14
  50. data/spec/choose/cardinality_spec.rb +32 -34
  51. data/spec/choose/mixin_examples.rb +6 -6
  52. data/spec/combinatorics_spec.rb +1 -1
  53. data/spec/derange/cardinality_spec.rb +1 -3
  54. data/spec/derange/mixin_examples.rb +6 -6
  55. data/spec/enumerator_spec.rb +1 -1
  56. data/spec/extensions/math_spec.rb +19 -19
  57. data/spec/extensions/range_spec.rb +12 -12
  58. data/spec/generator_spec.rb +1 -1
  59. data/spec/list_comprehension_spec.rb +10 -10
  60. data/spec/permute/cardinality_spec.rb +29 -31
  61. data/spec/permute/mixin_examples.rb +5 -5
  62. data/spec/power_set/cardinality_spec.rb +1 -3
  63. data/spec/power_set/mixin_examples.rb +4 -4
  64. data/spec/spec_helper.rb +2 -5
  65. metadata +26 -58
  66. data/.gemtest +0 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a2e5a4e1e77069bf882a67e27933b8640723ee43a209b3a7d4b442238a4d7e45
4
+ data.tar.gz: 595e89e295c7f9dae763f890f460f745edd743ac12340c5f8785677caa6a56b6
5
+ SHA512:
6
+ metadata.gz: 7eaec1f50156aa63c48212782b2cddd9a18b7dab7ba5986201f97c16b1ca9d01311b675c503b1cbe19ecb9ad63cef946a47f0eeef58742b62a8deb53b228ff30
7
+ data.tar.gz: af34206cde9e21f8637ac54449563456c81f939a3ca032c64e0a98fe5220918d5f9c03b6eefe3cf8c5b8c44280701c1121b7770ae1b4d6c8323eed0091cb2eb0
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ tests:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby:
12
+ - '3.0'
13
+ - '3.1'
14
+ - '3.2'
15
+ - '3.3'
16
+ - jruby
17
+ - truffleruby
18
+ name: Ruby ${{ matrix.ruby }}
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ - name: Install dependencies
26
+ run: bundle install --jobs 4 --retry 3
27
+ - name: Run tests
28
+ run: bundle exec rake test
data/.gitignore CHANGED
@@ -1,8 +1,8 @@
1
- pkg
2
- doc
3
- web
4
- tmp
1
+ /Gemfile.lock
2
+ /coverage
3
+ /doc
4
+ /pkg
5
+ /.yardoc
5
6
  .DS_Store
6
- .yardoc
7
7
  *.swp
8
8
  *~
data/ChangeLog.md CHANGED
@@ -1,3 +1,14 @@
1
+ ### 0.5.0 / 2024-01-25
2
+
3
+ * Require [ruby](http://www.ruby-lang.org/) >= 2.0.0.
4
+ * Switched to using `require_relative` to improve load-times.
5
+ * Added `# frozen_string_literal: true` to all files.
6
+
7
+ ### 0.4.4 / 2022-01-16
8
+
9
+ * Fixed a bug in {Combinatorics::Choose.cardinality} for when `0`
10
+ is given and `0` was returned instead of `1`.
11
+
1
12
  ### 0.4.3 / 2012-05-28
2
13
 
3
14
  * Fixed a typo in the gemspec, which incorrectly set
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'simplecov', '~> 0.20', require: false
11
+
12
+ gem 'kramdown'
13
+ gem 'redcarpet', platform: :mri
14
+ gem 'yard', '~> 0.9'
15
+ gem 'yard-spellcheck', require: false
16
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012 Hal Brodigan
1
+ Copyright (c) 2010-2024 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,15 +1,17 @@
1
1
  # Combinatorics
2
2
 
3
+ [![CI](https://github.com/postmodern/combinatorics/actions/workflows/ruby.yml/badge.svg)](https://github.com/postmodern/combinatorics/actions/workflows/ruby.yml)
4
+ [![Code Climate](https://codeclimate.com/github/postmodern/combinatorics.svg)](https://codeclimate.com/github/postmodern/combinatorics)
5
+
3
6
  * [Source](https://github.com/postmodern/combinatorics)
4
7
  * [Issues](https://github.com/postmodern/combinatorics/issues)
5
8
  * [Documentation](http://rubydoc.info/gems/combinatorics)
6
- * [Email](mailto:postmodern.mod3 at gmail.com)
7
9
 
8
10
  ## Description
9
11
 
10
12
  A collection of modules and methods for performing
11
13
  [Combinatoric](http://en.wikipedia.org/wiki/Combinatoric) calculations.
12
- Methods are defined to compute power sets, cartesian products, permutations,
14
+ Methods are defined to compute power sets, Cartesian products, permutations,
13
15
  combinations, and derangements.
14
16
 
15
17
  Note: this includes k-combinations and k-permutations, i.e. only generating
@@ -22,145 +24,180 @@ never complete due to exponential computational complexity.)
22
24
 
23
25
  ## Features
24
26
 
25
- * Adds Haskell/Python style list comprehensions via {Array#comprehension}.
27
+ * Adds Haskell/Python style list comprehensions via [Array#comprehension].
26
28
  * Provides reusable Combinatorics Mixins:
27
- * {Combinatorics::CartesianProduct}
28
- * {Combinatorics::Choose}
29
- * {Combinatorics::Derange}
30
- * {Combinatorics::Permute}
31
- * {Combinatorics::PowerSet}
32
- * Adds Combinatorics conveniance methods to {Array} and {Set}:
33
- * `cartesian_product`
34
- * `choose`
35
- * `derange`
36
- * `permute`
37
- * `powerset`
38
- * Adds conveniance methods:
39
- * {Range#&}
40
- * {Range#upto}
41
- * {Range#downto}
42
- * {Math.sigma}
43
- * {Math.pi}
44
- * {Math.factorial}
45
- * {Math.subfactorial}
29
+ * [Combinatorics::CartesianProduct]
30
+ * [Combinatorics::Choose]
31
+ * [Combinatorics::Derange]
32
+ * [Combinatorics::Permute]
33
+ * [Combinatorics::PowerSet]
34
+ * Adds Combinatorics core extension methods to {Array} and {Set}:
35
+ * [cartesian_product]
36
+ * [choose]
37
+ * [derange]
38
+ * [permute]
39
+ * [powerset]
40
+ * Adds additional core extension methods:
41
+ * [Range#&]
42
+ * [Range#upto]
43
+ * [Range#downto]
44
+ * [Math.sigma]
45
+ * [Math.pi]
46
+ * [Math.factorial]
47
+ * [Math.subfactorial]
48
+
49
+ [Array#comprehension]: https://rubydoc.info/gems/combinatorics/Array#comprehension-instance_method
50
+ [Combinatorics::CartesianProduct]: https://rubydoc.info/gems/combinatorics/Combinatorics/CartesianProduct
51
+ [Combinatorics::Choose]: https://rubydoc.info/gems/combinatorics/Combinatorics/Choose
52
+ [Combinatorics::Derange]: https://rubydoc.info/gems/combinatorics/Combinatorics/Derange
53
+ [Combinatorics::Permute]: https://rubydoc.info/gems/combinatorics/Combinatorics/Permute
54
+ [Combinatorics::PowerSet]: https://rubydoc.info/gems/combinatorics/Combinatorics/PowerSet
55
+ [cartesian_product]: https://rubydoc.info/gems/combinatorics/Combinatorics/CartesianProduct/Mixin#cartesian_product-instance_method
56
+ [choose]: https://rubydoc.info/gems/combinatorics/Combinatorics/Choose/Mixin#choose-instance_method
57
+ [derange]: https://rubydoc.info/gems/combinatorics/Combinatorics/Derange/Mixin#derange-instance_method
58
+ [permute]: https://rubydoc.info/gems/combinatorics/Combinatorics/Permute/Mixin#permute-instance_method
59
+ [powerset]: https://rubydoc.info/gems/combinatorics/Combinatorics/PowerSet/Mixin#powerset-instance_method
60
+ [Range#&]: https://rubydoc.info/gems/combinatorics/Range#&-instance_method
61
+ [Range#upto]: https://rubydoc.info/gems/combinatorics/Range#upto-instance_method
62
+ [Range#downto]: https://rubydoc.info/gems/combinatorics/Range#downto-instance_method
63
+ [Math.sigma]: https://rubydoc.info/gems/combinatorics/Math#sigma-class_method
64
+ [Math.pi]: https://rubydoc.info/gems/combinatorics/Math#pi-class_method
65
+ [Math.factorial]: https://rubydoc.info/gems/combinatorics/Math#factorial-class_method
66
+ [Math.subfactorial]: https://rubydoc.info/gems/combinatorics/Math#subfactorial-class_method
46
67
 
47
68
  ## Examples
48
69
 
49
70
  Power-set:
50
71
 
51
- Set['ab', 'cd', 'ef'].powerset
52
- # => [#<Set: {}>,
53
- #<Set: {"ef"}>,
54
- #<Set: {"cd"}>,
55
- #<Set: {"cd", "ef"}>,
56
- #<Set: {"ab"}>,
57
- #<Set: {"ab", "ef"}>,
58
- #<Set: {"ab", "cd"}>,
59
- #<Set: {"ab", "cd", "ef"}>]
72
+ ```ruby
73
+ Set['ab', 'cd', 'ef'].powerset
74
+ # => [#<Set: {}>,
75
+ #<Set: {"ef"}>,
76
+ #<Set: {"cd"}>,
77
+ #<Set: {"cd", "ef"}>,
78
+ #<Set: {"ab"}>,
79
+ #<Set: {"ab", "ef"}>,
80
+ #<Set: {"ab", "cd"}>,
81
+ #<Set: {"ab", "cd", "ef"}>]
82
+ ```
60
83
 
61
84
  Cartesian products:
62
85
 
63
- require 'combinatorics/cartesian_product'
64
-
65
- ['a', 'b', 'c'].cartesian_product([0, 1, 2]).to_a
66
- # => [["a", 0],
67
- ["b", 0],
68
- ["c", 0],
69
- ["a", 1],
70
- ["b", 1],
71
- ["c", 1],
72
- ["a", 2],
73
- ["b", 2],
74
- ["c", 2]]
86
+ ```ruby
87
+ require 'combinatorics/cartesian_product'
88
+
89
+ ['a', 'b', 'c'].cartesian_product([0, 1, 2]).to_a
90
+ # => [["a", 0],
91
+ ["b", 0],
92
+ ["c", 0],
93
+ ["a", 1],
94
+ ["b", 1],
95
+ ["c", 1],
96
+ ["a", 2],
97
+ ["b", 2],
98
+ ["c", 2]]
99
+ ```
75
100
 
76
101
  k-combinations:
77
102
 
78
- require 'combinatorics/choose'
79
-
80
- ('a'..'f').to_a.choose(2).to_a
81
- # => [["a", "b"],
82
- ["a", "c"],
83
- ["a", "d"],
84
- ["a", "e"],
85
- ["a", "f"],
86
- ["b", "c"],
87
- ["b", "d"],
88
- ["b", "e"],
89
- ["b", "f"],
90
- ["c", "d"],
91
- ["c", "e"],
92
- ["c", "f"],
93
- ["d", "e"],
94
- ["d", "f"],
95
- ["e", "f"]]
103
+ ```ruby
104
+ require 'combinatorics/choose'
105
+
106
+ ('a'..'f').to_a.choose(2).to_a
107
+ # => [["a", "b"],
108
+ ["a", "c"],
109
+ ["a", "d"],
110
+ ["a", "e"],
111
+ ["a", "f"],
112
+ ["b", "c"],
113
+ ["b", "d"],
114
+ ["b", "e"],
115
+ ["b", "f"],
116
+ ["c", "d"],
117
+ ["c", "e"],
118
+ ["c", "f"],
119
+ ["d", "e"],
120
+ ["d", "f"],
121
+ ["e", "f"]]
122
+ ```
96
123
 
97
124
  Derangements:
98
125
 
99
- require 'combinatorics/derange'
100
-
101
- [:_, :q, :z, :x].derange.to_a
102
- # => [[:q, :_, :x, :z],
103
- [:q, :z, :x, :_],
104
- [:q, :x, :_, :z],
105
- [:z, :_, :x, :q],
106
- [:z, :x, :_, :q],
107
- [:z, :x, :q, :_],
108
- [:x, :_, :q, :z],
109
- [:x, :z, :_, :q],
110
- [:x, :z, :q, :_]]
126
+ ```ruby
127
+ require 'combinatorics/derange'
128
+
129
+ [:_, :q, :z, :x].derange.to_a
130
+ # => [[:q, :_, :x, :z],
131
+ [:q, :z, :x, :_],
132
+ [:q, :x, :_, :z],
133
+ [:z, :_, :x, :q],
134
+ [:z, :x, :_, :q],
135
+ [:z, :x, :q, :_],
136
+ [:x, :_, :q, :z],
137
+ [:x, :z, :_, :q],
138
+ [:x, :z, :q, :_]]
139
+ ```
111
140
 
112
141
  Permutation cardinality:
113
142
 
114
- require 'combinatorics/permutation'
115
-
116
- Combinatorics::Permute.cardinality(128)
117
- # => 8256
143
+ ```ruby
144
+ require 'combinatorics/permutation'
145
+
146
+ Combinatorics::Permute.cardinality(128)
147
+ # => 8256
148
+ ```
118
149
 
119
150
  List comprehensions:
120
151
 
121
- require 'combinatorics/list_comprehension'
122
-
123
- [(0..10).step(2),('a'..'c')].comprehension.to_a
124
- # => [[0, "a"],
125
- [0, "b"],
126
- [0, "c"],
127
- [2, "a"],
128
- [2, "b"],
129
- [2, "c"],
130
- [4, "a"],
131
- [4, "b"],
132
- [4, "c"],
133
- [6, "a"],
134
- [6, "b"],
135
- [6, "c"],
136
- [8, "a"],
137
- [8, "b"],
138
- [8, "c"],
139
- [10, "a"],
140
- [10, "b"],
141
- [10, "c"]]
152
+ ```ruby
153
+ require 'combinatorics/list_comprehension'
154
+
155
+ [(0..10).step(2),('a'..'c')].comprehension.to_a
156
+ # => [[0, "a"],
157
+ [0, "b"],
158
+ [0, "c"],
159
+ [2, "a"],
160
+ [2, "b"],
161
+ [2, "c"],
162
+ [4, "a"],
163
+ [4, "b"],
164
+ [4, "c"],
165
+ [6, "a"],
166
+ [6, "b"],
167
+ [6, "c"],
168
+ [8, "a"],
169
+ [8, "b"],
170
+ [8, "c"],
171
+ [10, "a"],
172
+ [10, "b"],
173
+ [10, "c"]]
174
+ ```
142
175
 
143
176
  Find the intersecting sub-range between two ranges:
144
177
 
145
- (1..50) & (20..100)
146
- # => (20..50)
178
+ ```ruby
179
+ (1..50) & (20..100)
180
+ # => (20..50)
181
+ ```
147
182
 
148
183
  Enumerate over every sub-range between two ranges:
149
184
 
150
- (1..5).upto(2..10).to_a
151
- # => [1..5, 1..6, 1..7, 1..8, 1..9, 1..10,
152
- 2..5, 2..6, 2..7, 2..8, 2..9, 2..10]
185
+ ```ruby
186
+ (1..5).upto(2..10).to_a
187
+ # => [1..5, 1..6, 1..7, 1..8, 1..9, 1..10,
188
+ 2..5, 2..6, 2..7, 2..8, 2..9, 2..10]
189
+ ```
153
190
 
154
191
  ## Requirements
155
192
 
156
- * [ruby](http://www.ruby-lang.org/) >= 1.8.7
193
+ * [ruby](http://www.ruby-lang.org/) >= 2.0.0
157
194
 
158
195
  ## Install
159
196
 
160
- $ gem install combinatorics
197
+ ```shell
198
+ $ gem install combinatorics
199
+ ```
161
200
 
162
201
  ## Copyright
163
202
 
164
- Copyright (c) 2010-2012 Hal Brodigan
165
-
166
203
  See {file:LICENSE.txt} for license information.
data/Rakefile CHANGED
@@ -1,39 +1,13 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'rubygems/tasks'
2
+ Gem::Tasks.new
3
3
 
4
- begin
5
- gem 'rubygems-tasks', '~> 0.1'
6
- require 'rubygems/tasks'
7
-
8
- Gem::Tasks.new
9
- rescue LoadError => e
10
- warn e.message
11
- warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
12
- end
13
-
14
- begin
15
- gem 'rspec', '~> 2.4'
16
- require 'rspec/core/rake_task'
17
-
18
- RSpec::Core::RakeTask.new
19
- rescue LoadError => e
20
- task :spec do
21
- abort "Please run `gem install rspec` to install RSpec."
22
- end
23
- end
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
24
6
  task :test => :spec
25
7
  task :default => :spec
26
8
 
27
- begin
28
- gem 'yard', '~> 0.7'
29
- require 'yard'
30
-
31
- YARD::Rake::YardocTask.new
32
- rescue LoadError => e
33
- task :yard do
34
- abort "Please run `gem install yard` to install YARD."
35
- end
36
- end
9
+ require 'yard'
10
+ YARD::Rake::YardocTask.new
37
11
 
38
12
  task :benchmark do
39
13
  Dir.glob('benchmarks/*.rb') { |script| ruby(script) }
@@ -7,10 +7,7 @@ Gem::Specification.new do |gem|
7
7
 
8
8
  gem.name = gemspec.fetch('name')
9
9
  gem.version = gemspec.fetch('version') do
10
- lib_dir = File.join(File.dirname(__FILE__),'lib')
11
- $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
-
13
- require 'combinatorics/version'
10
+ require_relative 'lib/combinatorics/version'
14
11
  Combinatorics::VERSION
15
12
  end
16
13
 
@@ -20,6 +17,7 @@ Gem::Specification.new do |gem|
20
17
  gem.authors = Array(gemspec['authors'])
21
18
  gem.email = gemspec['email']
22
19
  gem.homepage = gemspec['homepage']
20
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
23
21
 
24
22
  glob = lambda { |patterns| gem.files & Dir[*patterns] }
25
23
 
data/gemspec.yml CHANGED
@@ -13,9 +13,13 @@ email:
13
13
  homepage: https://github.com/postmodern/combinatorics#readme
14
14
  has_yard: true
15
15
 
16
- required_ruby_version: ">= 1.8.7"
16
+ metadata:
17
+ documentation_uri: https://rubydoc.info/gems/combinatorics
18
+ source_code_uri: https://github.com/postmodern/combinatorics.rb
19
+ bug_tracker_uri: https://github.com/postmodern/combinatorics.rb/issues
20
+ changelog_uri: https://github.com/postmodern/combinatorics.rb/blob/master/ChangeLog.md
21
+
22
+ required_ruby_version: ">= 2.0.0"
17
23
 
18
24
  development_dependencies:
19
- rubygems-tasks: ~> 0.1
20
- rspec: ~> 2.4
21
- yard: ~> 0.7
25
+ bundler: ~> 2.0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Combinatorics
2
4
  #
3
5
  # @author duper <super@manson.vistech.net>
@@ -1,4 +1,6 @@
1
- require 'combinatorics/cartesian_product/mixin'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
2
4
 
3
5
  class Array
4
6
 
@@ -1,4 +1,6 @@
1
- require 'combinatorics/cartesian_product/mixin'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
2
4
 
3
5
  require 'set'
4
6
 
@@ -1,2 +1,4 @@
1
- require 'combinatorics/cartesian_product/extensions/array'
2
- require 'combinatorics/cartesian_product/extensions/set'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'extensions/array'
4
+ require_relative 'extensions/set'
@@ -1,4 +1,6 @@
1
- require 'combinatorics/list_comprehension'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../list_comprehension'
2
4
 
3
5
  module Combinatorics
4
6
  module CartesianProduct
@@ -1,3 +1,5 @@
1
- require 'combinatorics/cartesian_product/mixin'
2
- require 'combinatorics/cartesian_product/extensions'
3
- require 'combinatorics/cartesian_product/cardinality'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cartesian_product/mixin'
4
+ require_relative 'cartesian_product/extensions'
5
+ require_relative 'cartesian_product/cardinality'
@@ -1,4 +1,6 @@
1
- require 'combinatorics/extensions/math'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../extensions/math'
2
4
 
3
5
  module Combinatorics
4
6
  #
@@ -38,7 +40,7 @@ module Combinatorics
38
40
  raise(RangeError,"n must be non-negative") if n < 0
39
41
 
40
42
  case r
41
- when 0 then 0
43
+ when 0 then 1
42
44
  when nil then Math.factorial(n)
43
45
  else
44
46
  Math.factorial(n) / (Math.factorial(r) * Math.factorial(n - r))
@@ -1,4 +1,6 @@
1
- require 'combinatorics/choose/mixin'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
2
4
 
3
5
  class Array
4
6
  include Combinatorics::Choose::Mixin
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
4
+
1
5
  require 'set'
2
- require 'combinatorics/choose/mixin'
3
6
 
4
7
  class Set
5
8
  include Combinatorics::Choose::Mixin
@@ -1,2 +1,4 @@
1
- require 'combinatorics/choose/extensions/array'
2
- require 'combinatorics/choose/extensions/set'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'extensions/array'
4
+ require_relative 'extensions/set'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module Combinatorics
@@ -1,3 +1,5 @@
1
- require 'combinatorics/choose/mixin'
2
- require 'combinatorics/choose/extensions'
3
- require 'combinatorics/choose/cardinality'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'choose/mixin'
4
+ require_relative 'choose/extensions'
5
+ require_relative 'choose/cardinality'
@@ -1,4 +1,6 @@
1
- require 'combinatorics/extensions/math'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../extensions/math'
2
4
 
3
5
  module Combinatorics
4
6
  module Derange
@@ -1,4 +1,6 @@
1
- require 'combinatorics/derange/mixin'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
2
4
 
3
5
  class Array
4
6
  include Combinatorics::Derange::Mixin
@@ -1 +1,3 @@
1
- require 'combinatorics/derange/extensions/array'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'extensions/array'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Combinatorics
2
4
  module Derange
3
5
  #
@@ -1,3 +1,5 @@
1
- require 'combinatorics/derange/mixin'
2
- require 'combinatorics/derange/extensions'
3
- require 'combinatorics/derange/cardinality'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'derange/mixin'
4
+ require_relative 'derange/extensions'
5
+ require_relative 'derange/cardinality'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'enumerator'
2
4
 
3
5
  module Combinatorics