partitions?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

partitions?

stepharo
Hi

I'm looking for a method that given
     #(1 2 3)
returns
     #(
         #(1)
         #(2)
         #(3)
         #(1 2)
         #(2 3)
         #(1 3)
         #( 1 2 3))

Stef

Reply | Threaded
Open this post in threaded view
|

Re: partitions?

Michal Balda
Hi,
this solution is not exactly beautiful, but it works:

| input output |

input := #(1 2 3).

output :=
    Array streamContents: [
        :stream |
        1 to: input size do: [
            :take |
            input combinations: take atATimeDo: [
                :combination |
                stream nextPut: combination copy ] ] ].

output inspect


Michal



On 28.4.2015 20:02, stepharo wrote:
Hi

I'm looking for a method that given
    #(1 2 3)
returns
    #(
        #(1)
        #(2)
        #(3)
        #(1 2)
        #(2 3)
        #(1 3)
        #( 1 2 3))

Stef


Reply | Threaded
Open this post in threaded view
|

Re: partitions?

Sergio Fedi
Just in case, remember that the empty set. is also a partition​
Reply | Threaded
Open this post in threaded view
|

Re: partitions?

stepharo
In reply to this post by stepharo


The comment of the method
combinationsAt: jj in: aCollection after: nn do: aBlock

refers to

(1 to: 6) combinationsSize: 3 do: [:each | Transcript cr; show: each
printString]

but this method does not exist



Le 28/4/15 20:02, stepharo a écrit :

> Hi
>
> I'm looking for a method that given
>     #(1 2 3)
> returns
>     #(
>         #(1)
>         #(2)
>         #(3)
>         #(1 2)
>         #(2 3)
>         #(1 3)
>         #( 1 2 3))
>
> Stef
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: partitions?

stepharo
In reply to this post by Michal Balda
Hi michal

Thanks!

Stef


Le 28/4/15 21:07, Michal Balda a écrit :
Hi,
this solution is not exactly beautiful, but it works:

| input output |

input := #(1 2 3).

output :=
    Array streamContents: [
        :stream |
        1 to: input size do: [
            :take |
            input combinations: take atATimeDo: [
                :combination |
                stream nextPut: combination copy ] ] ].

output inspect


Michal



On 28.4.2015 20:02, stepharo wrote:
Hi

I'm looking for a method that given
    #(1 2 3)
returns
    #(
        #(1)
        #(2)
        #(3)
        #(1 2)
        #(2 3)
        #(1 3)
        #( 1 2 3))

Stef



Reply | Threaded
Open this post in threaded view
|

Re: partitions?

stepharo
In reply to this post by Sergio Fedi
So you mean that it should be added by default?


Le 28/4/15 21:24, Sergio Fedi a écrit :
> Just in case, remember that the empty set. is also a partition​