We tried to port this code to python and I learned that we cannot have a
set containing a set :(
and other uglies like len(str) but not str.len()
Stef
Le 22/10/15 22:58, stepharo a écrit :
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