Created
November 13, 2014 23:26
-
-
Save celbaz/ce208e6cbf46c5263502 to your computer and use it in GitHub Desktop.
a method for power sets
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
def subsets(array) | |
result = [[]] | |
array.each do |el| | |
result.each_with_index do |curr, i| | |
result << curr + [el] unless curr.include? el | |
end | |
end | |
result | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment