The wiki entry says powersets have 2^n elements where n is the number of 
elements in the original set. 2^n grows exponentially fast:

2^5   = 35
2^10  = 1024
2^50  = 1125899906842624
2^100 = 1267650600228229401496703205376

So if it's added, bounding it to only support small collections is not a bad 
idea. 2^30 = 1,073,741,824, so 30 element collections are too big (with 1GB 
address space). But <= 25 elements would be OK: 2^25 = 33,554,432

I actually needed something like this a few months ago, so there are usecases.

> Sent: Thursday, October 22, 2015 at 4:58 PM
> From: stepharo <[email protected]>
> To: "Pharo Development List" <[email protected]>
> Subject: [Pharo-dev] powerSet
>
> Hi
> 
> I was programming an exercise with one of my son (well in Python.... 
> arghhhhhh)
> and I end it up doing it in Pharo (I'm save now).
> 
> The idea was to write one function that computes the powerset
> 
> powerset(4)
>      = a Set(a Set(1) a Set(1 2) a Set(3) a Set(2) a Set(1 3) a Set(2 3) 
> a Set(1 2 3) a Set(4) a Set(1 4) a Set(2 4) a Set(1 2 4) a Set(3 4) a 
> Set(1 3 4) a Set(2 3 4) a Set(1 2 3 4))
> 
> I did it without thinking too much in fact
> 
> | s n ps |
> ps := Set new.
> 
> 1 to: ((2 raisedTo: 4) -1)
>      do: [ :i |
>          s := Set new.
>          n := 0.
>          1 to: 4 do: [ :b |
>              n := n + 1.
>              ((i bitAt: b) = 1 )
>                  ifTrue: [ s add: n].
>              ps add: s ]].
> ps
> 
> but I wonder if we want to add it to our lib.
> 
> Stef
> 
> 

Reply via email to