[Newbies] Re: Another extension proposal -> subsets
Klaus D. Witzel
klaus.witzel at cobss.com
Thu Jul 24 16:58:17 UTC 2008
On Thu, 24 Jul 2008 18:27:48 +0200, Cedrick wrote:
> or withNicolas suggestion:
>
> Set>>asPowerset
> | subset |
> subset := (OrderedCollection new: (2 raisedTo: self size))
> add: Set new;
> yourself.
> 1 to: self size do: [:subSize | "don't copy anymore as there is the
> Set conversion"
> self asArray combinations: subSize atATimeDo: [:subArray | subset
> add: subArray asSet]].
> ^ subset asSet
Ah, you francophones always want to see Blaise Pascal's triangle at work ;)
Didn't check #combinations:* implementation, does it avoid #includes: ?
> I'd still prefer #combinationsSize:do: instead of
> #combinations:atATimeDo:
+1 but it looks alt-w friendly already (like #detectSum: looks ;)
>>
>> How about naming
>>
>> Collection>>#asPowerset
>> ^ self asSet powersetInto: (Set new: (2 raisedTo: self size))
>>
>> with Set>>#powersetInto: and putting that into the next release.
>>
>> /Klaus
>>
More information about the Beginners
mailing list