<div dir="ltr">Googling &quot;smalltalk powerset&quot; turns this up: <a href="http://www.foldr.org/~michaelw/log/2005/09/">http://www.foldr.org/~michaelw/log/2005/09/</a><br><br><div class="gmail_quote">On Wed, Jul 23, 2008 at 11:51 AM, cdrick &lt;<a href="mailto:cdrick65@gmail.com">cdrick65@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">When we don&#39;t find method, we reinvent the wheel. Ok, so this is what<br>
happened with my quest on rounding float. So here is another example.<br>
I needed a method subsets ... to have all subsets of a Set...<br>
<br>
#(1 2 ) asSet subsets &quot; -&gt; a Set(a Set(1 2) a Set(1) a Set(2) a Set()) &quot;<br>
<br>
Is there already something ? I couldn&#39;t find so here is what I did ?<br>
probably hackish (because of the binary mask) so feel free to comment<br>
;)<br>
<br>
Set&gt;&gt;subsets<br>
| subsetsSize subsets workArray |<br>
 &nbsp; &nbsp; &nbsp; &nbsp;workArray := self asArray.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;subsetsSize := 2 raisedTo: self size.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;subsets := OrderedCollection new.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;1 to: subsetsSize do: [:ea |<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;subsets add: ((workArray masquedBy: (ea printStringBase: 2))<br>
asSet)]. &quot;masque par une conversion binaire&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;^subsets asSet &nbsp;&quot;could be an array of sets&quot;<br>
<br>
ArrayedCollection&gt;&gt;masquedBy: aBitString<br>
| result entry bitString |<br>
 &nbsp; &nbsp; &nbsp; &nbsp;entry := self reverse.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bitString := aBitString reverse.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;result := OrderedCollection new.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;1 to: (self size) do: [:ea |<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((bitString &nbsp;at: ea ifAbsent: []) = $1) ifTrue: [result add: (entry<br>
at: ea)]].<br>
 &nbsp; &nbsp; &nbsp; &nbsp;^result reverse<br>
<br>
Cédrick<br>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>