Created
July 9, 2016 02:03
-
-
Save topher6345/888adb3c18b2527ad76eba089484baf7 to your computer and use it in GitHub Desktop.
Power Set in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
class Set | |
def power_set | |
make_permutation = proc { |n| self.to_a.permutation(n).to_a.map(&:to_set).to_set} | |
Set.new([Set.new([]),(1..self.size).map(&make_permutation)]) | |
end | |
end | |
Set.new([1,2,3]).power_set |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment