epitools 0.4.16 → 0.4.17
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/epitools.gemspec +1 -1
- data/lib/epitools/basetypes.rb +3 -2
- data/spec/basetypes_spec.rb +2 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.17
|
data/epitools.gemspec
CHANGED
data/lib/epitools/basetypes.rb
CHANGED
@@ -392,8 +392,9 @@ module Enumerable
|
|
392
392
|
#
|
393
393
|
def powerset
|
394
394
|
# the bit pattern of the numbers from 0..2^(elements)-1 can be used to select the elements of the set...
|
395
|
-
|
396
|
-
|
395
|
+
a = to_a
|
396
|
+
(0...2**a.size).map do |bitmask|
|
397
|
+
a.select.with_index{ |e, i| bitmask[i] == 1 }
|
397
398
|
end
|
398
399
|
end
|
399
400
|
|
data/spec/basetypes_spec.rb
CHANGED
@@ -206,7 +206,8 @@ describe Enumerable do
|
|
206
206
|
end
|
207
207
|
|
208
208
|
it "powersets" do
|
209
|
-
|
209
|
+
[1,2,3].powerset.should == [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
|
210
|
+
Enum.new([1,2], :each).powerset.should == [[], [1], [2], [1, 2]]
|
210
211
|
end
|
211
212
|
|
212
213
|
end
|