Skip to content

Instantly share code, notes, and snippets.

@celbaz
Created November 13, 2014 23:26
Show Gist options
  • Save celbaz/ce208e6cbf46c5263502 to your computer and use it in GitHub Desktop.
Save celbaz/ce208e6cbf46c5263502 to your computer and use it in GitHub Desktop.
a method for power sets
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