combinatorics 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +8 -0
  3. data/Benchmarks.md +257 -26
  4. data/ChangeLog.md +12 -0
  5. data/LICENSE.txt +1 -2
  6. data/README.md +102 -32
  7. data/Rakefile +13 -2
  8. data/benchmarks/cartesian_product.rb +18 -0
  9. data/benchmarks/choose.rb +19 -0
  10. data/benchmarks/derange.rb +18 -0
  11. data/benchmarks/list_comprehension.rb +2 -5
  12. data/benchmarks/permute.rb +18 -0
  13. data/benchmarks/power_set.rb +18 -0
  14. data/combinatorics.gemspec +124 -7
  15. data/gemspec.yml +11 -6
  16. data/lib/combinatorics.rb +7 -0
  17. data/lib/combinatorics/cartesian_product.rb +3 -0
  18. data/lib/combinatorics/cartesian_product/cardinality.rb +45 -0
  19. data/lib/combinatorics/cartesian_product/extensions.rb +2 -0
  20. data/lib/combinatorics/cartesian_product/extensions/array.rb +7 -0
  21. data/lib/combinatorics/cartesian_product/extensions/set.rb +9 -0
  22. data/lib/combinatorics/cartesian_product/mixin.rb +57 -0
  23. data/lib/combinatorics/choose.rb +3 -0
  24. data/lib/combinatorics/choose/cardinality.rb +99 -0
  25. data/lib/combinatorics/choose/extensions.rb +2 -0
  26. data/lib/combinatorics/choose/extensions/array.rb +5 -0
  27. data/lib/combinatorics/choose/extensions/set.rb +6 -0
  28. data/lib/combinatorics/choose/mixin.rb +53 -0
  29. data/lib/combinatorics/derange.rb +3 -0
  30. data/lib/combinatorics/derange/cardinality.rb +23 -0
  31. data/lib/combinatorics/derange/extensions.rb +1 -0
  32. data/lib/combinatorics/derange/extensions/array.rb +5 -0
  33. data/lib/combinatorics/derange/mixin.rb +47 -0
  34. data/lib/combinatorics/enumerator.rb +2 -0
  35. data/lib/combinatorics/extensions/math.rb +177 -0
  36. data/lib/combinatorics/generator.rb +8 -1
  37. data/lib/combinatorics/permute.rb +3 -0
  38. data/lib/combinatorics/permute/cardinality.rb +98 -0
  39. data/lib/combinatorics/permute/extensions.rb +2 -0
  40. data/lib/combinatorics/permute/extensions/array.rb +7 -0
  41. data/lib/combinatorics/permute/extensions/set.rb +9 -0
  42. data/lib/combinatorics/permute/mixin.rb +48 -0
  43. data/lib/combinatorics/power_set.rb +1 -0
  44. data/lib/combinatorics/power_set/cardinality.rb +36 -0
  45. data/lib/combinatorics/power_set/mixin.rb +19 -22
  46. data/lib/combinatorics/version.rb +2 -2
  47. data/spec/cartesian_product/array_spec.rb +10 -0
  48. data/spec/cartesian_product/cardinality_spec.rb +64 -0
  49. data/spec/cartesian_product/mixin_examples.rb +98 -0
  50. data/spec/cartesian_product/set_spec.rb +10 -0
  51. data/spec/choose/array_spec.rb +9 -0
  52. data/spec/choose/cardinality_spec.rb +132 -0
  53. data/spec/choose/mixin_examples.rb +48 -0
  54. data/spec/choose/set_spec.rb +9 -0
  55. data/spec/derange/array_spec.rb +10 -0
  56. data/spec/derange/cardinality_spec.rb +14 -0
  57. data/spec/derange/mixin_examples.rb +52 -0
  58. data/spec/extensions/math_spec.rb +100 -0
  59. data/spec/extensions/range_spec.rb +1 -1
  60. data/spec/permute/array_spec.rb +10 -0
  61. data/spec/permute/cardinality_spec.rb +146 -0
  62. data/spec/permute/mixin_examples.rb +42 -0
  63. data/spec/permute/set_spec.rb +10 -0
  64. data/spec/power_set/array_spec.rb +3 -2
  65. data/spec/power_set/cardinality_spec.rb +32 -0
  66. data/spec/power_set/mixin_examples.rb +17 -8
  67. data/spec/power_set/set_spec.rb +3 -2
  68. data/spec/spec_helper.rb +5 -3
  69. metadata +114 -95
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ pkg
2
+ doc
3
+ web
4
+ tmp
5
+ .DS_Store
6
+ .yardoc
7
+ *.swp
8
+ *~
data/Benchmarks.md CHANGED
@@ -11,40 +11,271 @@ Benchmark machine specs:
11
11
 
12
12
  ## List Comprehensions:
13
13
 
14
- Ruby 1.9.2-p0 (2010-08-18 revision 29036) [x86_64-linux]:
14
+ Ruby 1.9.2-p290 (2011-07-09 revision 32553) [x86_64-linux]:
15
15
 
16
16
  user system total real
17
- singleton: 0.060000 0.010000 0.070000 ( 0.090075)
18
- single-enum: 0.020000 0.000000 0.020000 ( 0.035206)
19
- depth 1: 0.000000 0.000000 0.000000 ( 0.002489)
20
- depth 2: 0.240000 0.000000 0.240000 ( 0.306060)
21
- depth 3: 40.090000 0.250000 40.340000 ( 51.830667)
17
+ singleton: 0.050000 0.020000 0.070000 ( 0.081225)
18
+ single-enum: 0.000000 0.000000 0.000000 ( 0.009706)
19
+ depth 1: 0.000000 0.000000 0.000000 ( 0.000652)
20
+ depth 2: 0.070000 0.010000 0.080000 ( 0.084974)
21
+ depth 3: 5.670000 0.240000 5.910000 ( 6.623347)
22
22
 
23
- Ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]:
23
+ JRuby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768)
24
+ (OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]:
24
25
 
25
26
  user system total real
26
- singleton: 0.410000 0.290000 0.700000 ( 0.929625)
27
- single-enum: 0.050000 0.130000 0.180000 ( 0.348974)
28
- depth 1: 0.030000 0.050000 0.080000 ( 0.111043)
29
- depth 2: 15.650000 0.560000 16.210000 ( 23.012478)
30
- depth 3: 3239.310000 15.950000 3255.260000 (3739.261379)
27
+ singleton: 1.365000 0.000000 1.365000 ( 1.212000)
28
+ single-enum: 0.134000 0.000000 0.134000 ( 0.134000)
29
+ depth 1: 0.046000 0.000000 0.046000 ( 0.045000)
30
+ depth 2: 1.613000 0.000000 1.613000 ( 1.614000)
31
+ depth 3: 10.054000 0.000000 10.054000 ( 10.054000)
31
32
 
32
- JRuby 1.5.3 (ruby 1.8.7 patchlevel 249) (2010-09-28 7ca06d7)
33
- (OpenJDK 64-Bit Server VM 1.6.0_18) [amd64-java]:
33
+ Rubinius 2.0.0dev (1.8.7 5e67b11e yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]:
34
34
 
35
35
  user system total real
36
- singleton: 1.019000 0.000000 1.019000 ( 0.870000)
37
- single-enum: 0.325000 0.000000 0.325000 ( 0.325000)
38
- depth 1: 0.088000 0.000000 0.088000 ( 0.088000)
39
- depth 2: 5.045000 0.000000 5.045000 ( 5.044000)
40
- depth 3: 275.765000 0.000000 275.765000 (275.765000)
36
+ singleton: 0.802878 0.112983 0.915861 ( 1.722362)
37
+ single-enum: 0.128980 0.011998 0.140978 ( 0.176392)
38
+ depth 1: 0.000000 0.000000 0.000000 ( 0.000897)
39
+ depth 2: 0.058991 0.004999 0.063990 ( 0.143435)
40
+ depth 3: 3.483470 0.148977 3.632447 ( 5.156510)
41
41
 
42
- Rubinius 1.1.1dev (1.8.7 8bc2dc9a 2010-09-23 JI) [x86_64-unknown-linux-gnu]:
42
+ ## Cartesian Product
43
43
 
44
- user system total real
45
- singleton: 1.143827 0.088987 1.232814 ( 1.523531)
46
- single-enum: 0.313953 0.028996 0.342949 ( 0.423621)
47
- depth 1: 0.001999 0.000999 0.002998 ( 0.003840)
48
- depth 2: 1.051840 0.030996 1.082836 ( 1.293856)
49
- depth 3: 42.303569 5.777121 48.080690 ( 57.556785)
44
+ Ruby 1.9.2-p290 (2011-07-09 revision 32553) [x86_64-linux]:
45
+
46
+ user system total real
47
+ {100} x {100} 0.070000 0.000000 0.070000 ( 0.084734)
48
+ {200} x {200} 0.290000 0.020000 0.310000 ( 0.347752)
49
+ {400} x {400} 1.370000 0.070000 1.440000 ( 1.582130)
50
+ {800} x {800} 8.250000 0.370000 8.620000 ( 9.498290)
51
+
52
+ JRuby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768)
53
+ (OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]:
54
+
55
+ user system total real
56
+ {100} x {100} 2.469000 0.000000 2.469000 ( 2.349000)
57
+ {200} x {200} 2.575000 0.000000 2.575000 ( 2.574000)
58
+ {400} x {400} 2.354000 0.000000 2.354000 ( 2.354000)
59
+ {800} x {800} 7.730000 0.000000 7.730000 ( 7.730000)
60
+
61
+ Rubinius 2.0.0dev (1.8.7 5e67b11e yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]:
62
+
63
+ user system total real
64
+ {100} x {100} 0.114982 0.051992 0.166974 ( 1.184129)
65
+ {200} x {200} 0.391941 0.159976 0.551917 ( 1.396105)
66
+ {400} x {400} 1.333797 0.653901 1.987698 ( 3.120384)
67
+ {800} x {800} 5.961093 2.614602 8.575695 ( 13.643119)
68
+
69
+ ## Choose
70
+
71
+ Ruby 1.9.2-p290 (2011-07-09 revision 32553) [x86_64-linux]:
72
+
73
+ user system total real
74
+ n=20 k=1 0.000000 0.000000 0.000000 ( 0.000172)
75
+ n=20 k=2 0.010000 0.000000 0.010000 ( 0.003592)
76
+ n=20 k=3 0.010000 0.000000 0.010000 ( 0.017710)
77
+ n=20 k=4 0.040000 0.000000 0.040000 ( 0.060566)
78
+ n=20 k=5 0.180000 0.010000 0.190000 ( 0.211709)
79
+ n=20 k=6 0.490000 0.030000 0.520000 ( 0.583004)
80
+ n=20 k=7 1.110000 0.070000 1.180000 ( 1.307065)
81
+ n=20 k=8 1.980000 0.050000 2.030000 ( 2.204111)
82
+ n=20 k=9 2.770000 0.120000 2.890000 ( 3.221468)
83
+ n=20 k=10 3.310000 0.150000 3.460000 ( 3.904973)
84
+ n=20 k=11 3.120000 0.150000 3.270000 ( 4.085721)
85
+ n=20 k=12 2.520000 0.140000 2.660000 ( 3.139445)
86
+ n=20 k=13 1.570000 0.060000 1.630000 ( 1.853883)
87
+ n=20 k=14 0.820000 0.040000 0.860000 ( 1.142598)
88
+ n=20 k=15 0.350000 0.020000 0.370000 ( 0.436363)
89
+ n=20 k=16 0.110000 0.000000 0.110000 ( 0.141398)
90
+ n=20 k=17 0.030000 0.010000 0.040000 ( 0.047691)
91
+ n=20 k=18 0.000000 0.000000 0.000000 ( 0.003746)
92
+ n=20 k=19 0.000000 0.000000 0.000000 ( 0.000438)
93
+ n=20 k=20 0.000000 0.000000 0.000000 ( 0.000043)
94
+
95
+ JRuby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768)
96
+ (OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]:
97
+
98
+ user system total real
99
+ n=20 k=1 0.271000 0.000000 0.271000 ( 0.048000)
100
+ n=20 k=2 0.163000 0.000000 0.163000 ( 0.163000)
101
+ n=20 k=3 0.184000 0.000000 0.184000 ( 0.184000)
102
+ n=20 k=4 0.759000 0.000000 0.759000 ( 0.759000)
103
+ n=20 k=5 1.157000 0.000000 1.157000 ( 1.157000)
104
+ n=20 k=6 1.116000 0.000000 1.116000 ( 1.116000)
105
+ n=20 k=7 0.490000 0.000000 0.490000 ( 0.490000)
106
+ n=20 k=8 0.632000 0.000000 0.632000 ( 0.632000)
107
+ n=20 k=9 0.907000 0.000000 0.907000 ( 0.908000)
108
+ n=20 k=10 1.040000 0.000000 1.040000 ( 1.040000)
109
+ n=20 k=11 0.991000 0.000000 0.991000 ( 0.991000)
110
+ n=20 k=12 0.784000 0.000000 0.784000 ( 0.784000)
111
+ n=20 k=13 0.513000 0.000000 0.513000 ( 0.514000)
112
+ n=20 k=14 0.285000 0.000000 0.285000 ( 0.285000)
113
+ n=20 k=15 0.141000 0.000000 0.141000 ( 0.142000)
114
+ n=20 k=16 0.045000 0.000000 0.045000 ( 0.045000)
115
+ n=20 k=17 0.009000 0.000000 0.009000 ( 0.009000)
116
+ n=20 k=18 0.004000 0.000000 0.004000 ( 0.004000)
117
+ n=20 k=19 0.001000 0.000000 0.001000 ( 0.001000)
118
+ n=20 k=20 0.000000 0.000000 0.000000 ( 0.000000)
119
+
120
+ Rubinius 2.0.0dev (1.8.7 5e67b11e yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]:
121
+
122
+ user system total real
123
+ n=20 k=1 0.001000 0.000000 0.001000 ( 0.001005)
124
+ n=20 k=2 0.005999 0.000000 0.005999 ( 0.016681)
125
+ n=20 k=3 0.051992 0.002000 0.053992 ( 0.177731)
126
+ n=20 k=4 0.159976 0.005999 0.165975 ( 0.564428)
127
+ n=20 k=5 0.412938 0.016998 0.429936 ( 1.410280)
128
+ n=20 k=6 1.045841 0.034994 1.080835 ( 1.220624)
129
+ n=20 k=7 2.234661 0.073989 2.308650 ( 2.514775)
130
+ n=20 k=8 3.821419 0.157976 3.979395 ( 4.479381)
131
+ n=20 k=9 5.377183 0.230965 5.608148 ( 6.545616)
132
+ n=20 k=10 6.270047 0.271958 6.542005 ( 7.481663)
133
+ n=20 k=11 6.056079 0.201970 6.258049 ( 7.179931)
134
+ n=20 k=12 4.684288 0.237963 4.922251 ( 5.829043)
135
+ n=20 k=13 3.066534 0.122982 3.189516 ( 3.633006)
136
+ n=20 k=14 1.716739 0.060990 1.777729 ( 2.083863)
137
+ n=20 k=15 0.708892 0.031996 0.740888 ( 0.814869)
138
+ n=20 k=16 0.233965 0.006999 0.240964 ( 0.272663)
139
+ n=20 k=17 0.057992 0.000999 0.058991 ( 0.075194)
140
+ n=20 k=18 0.008999 0.001000 0.009999 ( 0.015695)
141
+ n=20 k=19 0.001999 0.000000 0.001999 ( 0.001539)
142
+ n=20 k=20 0.000000 0.000000 0.000000 ( 0.000253)
143
+
144
+ ## Permute
145
+
146
+ Ruby 1.9.2-p290 (2011-07-09 revision 32553) [x86_64-linux]:
147
+
148
+ user system total real
149
+ r=1 0.000000 0.000000 0.000000 ( 0.000029)
150
+ r=2 0.000000 0.000000 0.000000 ( 0.000029)
151
+ r=3 0.010000 0.000000 0.010000 ( 0.002234)
152
+ r=4 0.000000 0.000000 0.000000 ( 0.002388)
153
+ r=5 0.020000 0.000000 0.020000 ( 0.028709)
154
+ r=6 0.100000 0.000000 0.100000 ( 0.119063)
155
+ r=7 0.380000 0.030000 0.410000 ( 0.462036)
156
+ r=8 1.210000 0.080000 1.290000 ( 1.447420)
157
+ r=9 2.510000 0.130000 2.640000 ( 2.919967)
158
+ r=10 2.840000 0.200000 3.040000 ( 3.664906)
159
+
160
+ JRuby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768)
161
+ (OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]:
162
+
163
+ user system total real
164
+ r=1 0.274000 0.000000 0.274000 ( 0.041000)
165
+ r=2 0.001000 0.000000 0.001000 ( 0.001000)
166
+ r=3 0.012000 0.000000 0.012000 ( 0.012000)
167
+ r=4 0.154000 0.000000 0.154000 ( 0.154000)
168
+ r=5 0.306000 0.000000 0.306000 ( 0.307000)
169
+ r=6 0.081000 0.000000 0.081000 ( 0.081000)
170
+ r=7 0.168000 0.000000 0.168000 ( 0.168000)
171
+ r=8 0.516000 0.000000 0.516000 ( 0.517000)
172
+ r=9 1.224000 0.000000 1.224000 ( 1.224000)
173
+ r=10 1.649000 0.000000 1.649000 ( 1.649000)
174
+
175
+ Rubinius 2.0.0dev (1.8.7 5e67b11e yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]:
176
+
177
+ user system total real
178
+ r=1 0.001000 0.000000 0.001000 ( 0.000062)
179
+ r=2 0.001000 0.000000 0.001000 ( 0.004535)
180
+ r=3 0.006000 0.000000 0.006000 ( 0.016175)
181
+ r=4 0.049993 0.003000 0.052993 ( 0.171867)
182
+ r=5 0.153976 0.012998 0.166974 ( 0.584311)
183
+ r=6 0.578912 0.020997 0.599909 ( 0.654977)
184
+ r=7 2.694590 0.106984 2.801574 ( 3.170215)
185
+ r=8 9.167606 0.337948 9.505554 ( 10.952164)
186
+ r=9 21.419744 0.785881 22.205625 ( 24.619187)
187
+ r=10 29.557506 1.087834 30.645340 ( 34.234011)
188
+
189
+ ## Derange
190
+
191
+ Ruby 1.9.2-p290 (2011-07-09 revision 32553) [x86_64-linux]:
192
+
193
+ user system total real
194
+ n=1 0.000000 0.000000 0.000000 ( 0.000021)
195
+ n=2 0.000000 0.000000 0.000000 ( 0.000041)
196
+ n=3 0.000000 0.000000 0.000000 ( 0.000021)
197
+ n=4 0.000000 0.000000 0.000000 ( 0.000069)
198
+ n=5 0.000000 0.000000 0.000000 ( 0.000393)
199
+ n=6 0.000000 0.000000 0.000000 ( 0.002281)
200
+ n=7 0.020000 0.010000 0.030000 ( 0.028188)
201
+ n=8 0.170000 0.000000 0.170000 ( 0.207589)
202
+ n=9 1.630000 0.070000 1.700000 ( 1.974767)
203
+ n=10 17.200000 0.670000 17.870000 ( 20.047089)
204
+
205
+ JRuby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768)
206
+ (OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]:
207
+
208
+ user system total real
209
+ n=1 0.150000 0.000000 0.150000 ( 0.023000)
210
+ n=2 0.003000 0.000000 0.003000 ( 0.003000)
211
+ n=3 0.001000 0.000000 0.001000 ( 0.001000)
212
+ n=4 0.006000 0.000000 0.006000 ( 0.007000)
213
+ n=5 0.022000 0.000000 0.022000 ( 0.022000)
214
+ n=6 0.173000 0.000000 0.173000 ( 0.173000)
215
+ n=7 1.045000 0.000000 1.045000 ( 1.045000)
216
+ n=8 0.821000 0.000000 0.821000 ( 0.821000)
217
+ n=9 1.917000 0.000000 1.917000 ( 1.917000)
218
+ n=10 25.652000 0.000000 25.652000 ( 25.652000)
219
+
220
+ Rubinius 2.0.0dev (1.8.7 5e67b11e yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]:
221
+
222
+ user system total real
223
+ n=1 0.000000 0.000000 0.000000 ( 0.000025)
224
+ n=2 0.000000 0.000000 0.000000 ( 0.000394)
225
+ n=3 0.000000 0.000000 0.000000 ( 0.000145)
226
+ n=4 0.000000 0.000000 0.000000 ( 0.000637)
227
+ n=5 0.004000 0.000000 0.004000 ( 0.010315)
228
+ n=6 0.036994 0.003000 0.039994 ( 0.151349)
229
+ n=7 0.130980 0.009998 0.140978 ( 0.584286)
230
+ n=8 0.579912 0.028996 0.608908 ( 0.946738)
231
+ n=9 5.563154 0.191970 5.755124 ( 6.588485)
232
+ n=10 59.973882 2.427631 62.401513 ( 80.877847)
233
+
234
+ ## Power Set
235
+
236
+ Ruby 1.9.2-p290 (2011-07-09 revision 32553) [x86_64-linux]:
237
+
238
+ user system total real
239
+ n=10 0.000000 0.000000 0.000000 ( 0.015275)
240
+ n=11 0.020000 0.000000 0.020000 ( 0.033685)
241
+ n=12 0.050000 0.000000 0.050000 ( 0.063667)
242
+ n=13 0.110000 0.010000 0.120000 ( 0.131612)
243
+ n=14 0.230000 0.010000 0.240000 ( 0.276595)
244
+ n=15 0.500000 0.010000 0.510000 ( 0.559058)
245
+ n=16 1.040000 0.050000 1.090000 ( 1.222567)
246
+ n=17 2.110000 0.120000 2.230000 ( 2.607683)
247
+ n=18 4.410000 0.230000 4.640000 ( 5.223074)
248
+ n=19 9.240000 0.460000 9.700000 ( 10.995905)
249
+ n=20 19.280000 0.810000 20.090000 ( 23.152085)
250
+
251
+ JRuby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768)
252
+ (OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]:
253
+
254
+ user system total real
255
+ n=10 0.539000 0.000000 0.539000 ( 0.369000)
256
+ n=11 0.609000 0.000000 0.609000 ( 0.609000)
257
+ n=12 0.490000 0.000000 0.490000 ( 0.490000)
258
+ n=13 0.701000 0.000000 0.701000 ( 0.701000)
259
+ n=14 1.013000 0.000000 1.013000 ( 1.013000)
260
+ n=15 0.729000 0.000000 0.729000 ( 0.729000)
261
+ n=16 0.306000 0.000000 0.306000 ( 0.306000)
262
+ n=17 0.601000 0.000000 0.601000 ( 0.601000)
263
+ n=18 1.291000 0.000000 1.291000 ( 1.291000)
264
+ n=19 2.591000 0.000000 2.591000 ( 2.591000)
265
+ n=20 5.573000 0.000000 5.573000 ( 5.573000)
266
+
267
+ Rubinius 2.0.0dev (1.8.7 5e67b11e yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]:
268
+
269
+ user system total real
270
+ n=10 0.050992 0.009999 0.060991 ( 0.196739)
271
+ n=11 0.088986 0.011998 0.100984 ( 0.295952)
272
+ n=12 0.141979 0.003999 0.145978 ( 0.632228)
273
+ n=13 0.248962 0.012998 0.261960 ( 0.939763)
274
+ n=14 0.482927 0.015998 0.498925 ( 0.562893)
275
+ n=15 0.988849 0.035994 1.024843 ( 1.134604)
276
+ n=16 2.034691 0.076988 2.111679 ( 2.342626)
277
+ n=17 4.188363 0.158976 4.347339 ( 4.882135)
278
+ n=18 8.595693 0.347947 8.943640 ( 10.191949)
279
+ n=19 17.662315 0.674898 18.337213 ( 20.490505)
280
+ n=20 36.434461 1.536766 37.971227 ( 42.821087)
50
281
 
data/ChangeLog.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 0.4.0 / 2011-10-15
2
+
3
+ * Added {Math.sigma}.
4
+ * Added {Math.pi}.
5
+ * Added {Math.factorial}.
6
+ * Added {Math.subfactorial}.
7
+ * Added {Combinatorics::CartesianProduct}.
8
+ * Added {Combinatorics::Choose}.
9
+ * Added {Combinatorics::Derange}.
10
+ * Added {Combinatorics::Permute}.
11
+ * Added {Combinatorics::PowerSet}.
12
+
1
13
  ### 0.3.1 / 2010-10-26
2
14
 
3
15
  * Do not call `enum_for` on `Enumerator` objects passed to
data/LICENSE.txt CHANGED
@@ -1,5 +1,4 @@
1
-
2
- Copyright (c) 2010 Hal Brodigan
1
+ Copyright (c) 2010-2011 Hal Brodigan
3
2
 
4
3
  Permission is hereby granted, free of charge, to any person obtaining
5
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,45 +1,52 @@
1
1
  # Combinatorics
2
2
 
3
- * [github.com/postmodern/combinatorics](http://github.com/postmodern/combinatorics)
4
- * [github.com/postmodern/combinatorics/issues](http://github.com/postmodern/combinatorics/issues)
5
- * Postmodern (postmodern.mod3 at gmail.com)
3
+ * [Source](http://github.com/postmodern/combinatorics)
4
+ * [Issues](http://github.com/postmodern/combinatorics/issues)
5
+ * [Documentation](http://rubydoc.info/gems/combinatorics)
6
+ * [Email](mailto:postmodern.mod3 at gmail.com)
6
7
 
7
8
  ## Description
8
9
 
9
10
  A collection of modules and methods for performing
10
11
  [Combinatoric](http://en.wikipedia.org/wiki/Combinatoric) calculations.
12
+ Methods are defined to compute power sets, cartesian products, permutations,
13
+ combinations, and derangements.
14
+
15
+ Note: this includes k-combinations and k-permutations, i.e. only generating
16
+ resultant sets of a given size. Each set theory operation method supports block
17
+ arguments to allow continuous code execution during the combinatoric set
18
+ generation process. Each combinatoric operation implementation also supports a
19
+ `cardinality` method which determines the total number of subsets that will be
20
+ created beforehand (to aid in the avoidance of starting an operation which will
21
+ never complete due to exponential computational complexity.)
11
22
 
12
23
  ## Features
13
24
 
14
- * Adds `powerset` to {Array} and {Set}.
15
- * Added {Range#&}, {Range#upto} and {Range#downto}.
16
25
  * Adds Haskell/Python style list comprehensions via {Array#comprehension}.
26
+ * 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}
17
46
 
18
47
  ## Examples
19
48
 
20
- Power-set of an {Array}:
21
-
22
- require 'combinatorics/power_set'
23
-
24
- [1,2,3,4].powerset
25
- # => [[],
26
- [4],
27
- [3],
28
- [3, 4],
29
- [2],
30
- [2, 4],
31
- [2, 3],
32
- [2, 3, 4],
33
- [1],
34
- [1, 4],
35
- [1, 3],
36
- [1, 3, 4],
37
- [1, 2],
38
- [1, 2, 4],
39
- [1, 2, 3],
40
- [1, 2, 3, 4]]
41
-
42
- Power-set of a {Set}:
49
+ Power-set:
43
50
 
44
51
  Set['ab', 'cd', 'ef'].powerset
45
52
  # => [#<Set: {}>,
@@ -86,13 +93,76 @@ List comprehensions:
86
93
  [10, "b"],
87
94
  [10, "c"]]
88
95
 
96
+ Cartesian products:
97
+
98
+ require 'combinatorics/cartesian_product'
99
+
100
+ ['a', 'b', 'c'].cartesian_product([0, 1, 2]).to_a
101
+ # => [["a", 0],
102
+ ["b", 0],
103
+ ["c", 0],
104
+ ["a", 1],
105
+ ["b", 1],
106
+ ["c", 1],
107
+ ["a", 2],
108
+ ["b", 2],
109
+ ["c", 2]]
110
+
111
+ k-combinations:
112
+
113
+ require 'combinatorics/choose'
114
+
115
+ ('a'..'f').to_a.choose(2).to_a
116
+ # => [["a", "b"],
117
+ ["a", "c"],
118
+ ["a", "d"],
119
+ ["a", "e"],
120
+ ["a", "f"],
121
+ ["b", "c"],
122
+ ["b", "d"],
123
+ ["b", "e"],
124
+ ["b", "f"],
125
+ ["c", "d"],
126
+ ["c", "e"],
127
+ ["c", "f"],
128
+ ["d", "e"],
129
+ ["d", "f"],
130
+ ["e", "f"]]
131
+
132
+ Derangements:
133
+
134
+ require 'combinatorics/derange'
135
+
136
+ [:_, :q, :z, :x].derange.to_a
137
+ # => [[:q, :_, :x, :z],
138
+ [:q, :z, :x, :_],
139
+ [:q, :x, :_, :z],
140
+ [:z, :_, :x, :q],
141
+ [:z, :x, :_, :q],
142
+ [:z, :x, :q, :_],
143
+ [:x, :_, :q, :z],
144
+ [:x, :z, :_, :q],
145
+ [:x, :z, :q, :_]]
146
+
147
+ Permutation cardinality:
148
+
149
+ require 'combinatorics/permutation'
150
+
151
+ include Combinatorics::Permute
152
+
153
+ Combinatorics::Permute::cardinality(128)
154
+ # => 8256
155
+
156
+ ## Requirements
157
+
158
+ * [ruby](http://www.ruby-lang.org/) >= 1.8.7
159
+
89
160
  ## Install
90
161
 
91
- $ sudo gem install combinatorics
162
+ $ sudo gem install combinatorics
92
163
 
93
- ## License
164
+ ## Copyright
94
165
 
95
- Copyright (c) 2010 Hal Brodigan
166
+ Copyright (c) 2010-2011 Hal Brodigan
96
167
 
97
168
  See {file:LICENSE.txt} for license information.
98
-