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
_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners