combinatorics 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +5 -5
- data/ChangeLog.md +11 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +1 -1
- data/README.md +144 -107
- data/Rakefile +6 -32
- data/combinatorics.gemspec +2 -4
- data/gemspec.yml +8 -4
- data/lib/combinatorics/cartesian_product/cardinality.rb +2 -0
- data/lib/combinatorics/cartesian_product/extensions/array.rb +3 -1
- data/lib/combinatorics/cartesian_product/extensions/set.rb +3 -1
- data/lib/combinatorics/cartesian_product/extensions.rb +4 -2
- data/lib/combinatorics/cartesian_product/mixin.rb +3 -1
- data/lib/combinatorics/cartesian_product.rb +5 -3
- data/lib/combinatorics/choose/cardinality.rb +4 -2
- data/lib/combinatorics/choose/extensions/array.rb +3 -1
- data/lib/combinatorics/choose/extensions/set.rb +4 -1
- data/lib/combinatorics/choose/extensions.rb +4 -2
- data/lib/combinatorics/choose/mixin.rb +2 -0
- data/lib/combinatorics/choose.rb +5 -3
- data/lib/combinatorics/derange/cardinality.rb +3 -1
- data/lib/combinatorics/derange/extensions/array.rb +3 -1
- data/lib/combinatorics/derange/extensions.rb +3 -1
- data/lib/combinatorics/derange/mixin.rb +2 -0
- data/lib/combinatorics/derange.rb +5 -3
- data/lib/combinatorics/enumerator.rb +2 -0
- data/lib/combinatorics/extensions/math.rb +2 -0
- data/lib/combinatorics/extensions/range.rb +2 -0
- data/lib/combinatorics/extensions.rb +3 -1
- data/lib/combinatorics/generator.rb +3 -1
- data/lib/combinatorics/list_comprehension.rb +3 -1
- data/lib/combinatorics/permute/cardinality.rb +3 -1
- data/lib/combinatorics/permute/extensions/array.rb +3 -1
- data/lib/combinatorics/permute/extensions/set.rb +3 -1
- data/lib/combinatorics/permute/extensions.rb +4 -2
- data/lib/combinatorics/permute/mixin.rb +2 -0
- data/lib/combinatorics/permute.rb +5 -3
- data/lib/combinatorics/power_set/cardinality.rb +3 -1
- data/lib/combinatorics/power_set/extensions/array.rb +3 -1
- data/lib/combinatorics/power_set/extensions/set.rb +3 -1
- data/lib/combinatorics/power_set/extensions.rb +4 -2
- data/lib/combinatorics/power_set/mixin.rb +2 -0
- data/lib/combinatorics/power_set.rb +5 -3
- data/lib/combinatorics/version.rb +3 -1
- data/lib/combinatorics.rb +12 -10
- data/spec/cartesian_product/cardinality_spec.rb +14 -16
- data/spec/cartesian_product/mixin_examples.rb +14 -14
- data/spec/choose/cardinality_spec.rb +32 -34
- data/spec/choose/mixin_examples.rb +6 -6
- data/spec/combinatorics_spec.rb +1 -1
- data/spec/derange/cardinality_spec.rb +1 -3
- data/spec/derange/mixin_examples.rb +6 -6
- data/spec/enumerator_spec.rb +1 -1
- data/spec/extensions/math_spec.rb +19 -19
- data/spec/extensions/range_spec.rb +12 -12
- data/spec/generator_spec.rb +1 -1
- data/spec/list_comprehension_spec.rb +10 -10
- data/spec/permute/cardinality_spec.rb +29 -31
- data/spec/permute/mixin_examples.rb +5 -5
- data/spec/power_set/cardinality_spec.rb +1 -3
- data/spec/power_set/mixin_examples.rb +4 -4
- data/spec/spec_helper.rb +2 -5
- metadata +26 -58
- 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
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
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,
|
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
|
27
|
+
* Adds Haskell/Python style list comprehensions via [Array#comprehension].
|
26
28
|
* Provides reusable Combinatorics Mixins:
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
30
|
-
*
|
31
|
-
*
|
32
|
-
* Adds Combinatorics
|
33
|
-
*
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
37
|
-
*
|
38
|
-
* Adds
|
39
|
-
*
|
40
|
-
*
|
41
|
-
*
|
42
|
-
*
|
43
|
-
*
|
44
|
-
*
|
45
|
-
*
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
143
|
+
```ruby
|
144
|
+
require 'combinatorics/permutation'
|
145
|
+
|
146
|
+
Combinatorics::Permute.cardinality(128)
|
147
|
+
# => 8256
|
148
|
+
```
|
118
149
|
|
119
150
|
List comprehensions:
|
120
151
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
-
|
146
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
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/) >=
|
193
|
+
* [ruby](http://www.ruby-lang.org/) >= 2.0.0
|
157
194
|
|
158
195
|
## Install
|
159
196
|
|
160
|
-
|
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
|
-
|
1
|
+
require 'rubygems/tasks'
|
2
|
+
Gem::Tasks.new
|
3
3
|
|
4
|
-
|
5
|
-
|
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
|
-
|
28
|
-
|
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) }
|
data/combinatorics.gemspec
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
20
|
-
rspec: ~> 2.4
|
21
|
-
yard: ~> 0.7
|
25
|
+
bundler: ~> 2.0
|
@@ -1,3 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
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
|
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))
|
data/lib/combinatorics/choose.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'choose/mixin'
|
4
|
+
require_relative 'choose/extensions'
|
5
|
+
require_relative 'choose/cardinality'
|
@@ -1,3 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'derange/mixin'
|
4
|
+
require_relative 'derange/extensions'
|
5
|
+
require_relative 'derange/cardinality'
|