Skip to content

Instantly share code, notes, and snippets.

@austintaylor
Created April 25, 2011 19:16
Show Gist options
  • Save austintaylor/941024 to your computer and use it in GitHub Desktop.
Save austintaylor/941024 to your computer and use it in GitHub Desktop.
Powerset: Haskell vs. Ruby
import Control.Monad (filterM)
powerset :: [a] -> [[a]]
powerset = filterM (\x -> [True, False])
class Array
def powerset
return [[]] if empty?
self[1..-1].powerset.map {|a| [self[0]] + a} + self[1..-1].powerset
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment