From: Mathieu Bouchard Date: 2001-05-27T12:16:22+09:00 Subject: [ruby-talk:15787] Re: Subsets of a set On Sun, 27 May 2001, Harry Ohlsen wrote: > Harry Ohlsen wrote: > By the way, I'd be happy to accept a routine which returns the set of > ALL subsets (ie, the power set), because I could easily code something > to extract elements of a given size from that. Mine is not recursive, but it works anyway. class Array; def power_each (0...2**length).each {|i| yield *indices(*(0...length).find_all {|j| i&(1<0 }) } end end [0.618,true,42,"towel",:foo].power_each {|*x| p x} matju