[Newbies] Re: Another extension proposal -> subsets
cdrick65 at gmail.com
Thu Jul 24 16:27:48 UTC 2008
or withNicolas suggestion:
| subset |
subset := (OrderedCollection new: (2 raisedTo: self size))
add: Set new;
1 to: self size do: [:subSize | "don't copy anymore as there is the
self asArray combinations: subSize atATimeDo: [:subArray | subset
add: subArray asSet]].
^ subset asSet
I'd still prefer #combinationsSize:do: instead of #combinations:atATimeDo:
> How about naming
> ^ self asSet powersetInto: (Set new: (2 raisedTo: self size))
> with Set>>#powersetInto: and putting that into the next release.
More information about the Beginners