Created
October 31, 2014 17:26
-
-
Save macabreb0b/fcfe61f09f08065f178f to your computer and use it in GitHub Desktop.
This file contains 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) | |
return [[]] if array.empty? | |
first = array.shift | |
subs = subsets(array) | |
other_subs = subs.map do |sub| | |
sub = sub + [first] | |
end | |
other_subs + subs | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment