[Squeak] Newbie permutations

Duane Maxwell dmaxwell at san.rr.com
Tue Apr 9 07:08:41 UTC 2002


From: "Michael Grant" <mwgrant2001 at yahoo.com>
> The following expression (Squeak 3.0)writes the
> permutations of
> #(1 3 5) to the Transcript as expected:
> 
> #(1 3 5) permutationsDo: [:each | Transcript cr;
>                                   show: each
> printString].
> 
> However, I can not figure out how to save the
> permutations to a
> variable, say 'Foo', with Foo having the value:
> 
>  #(#(1 3 5) #(1 5 3) #(3 1 5)...)
> 
> My efforts have typically ended up as #(nil nil ...),
> or an error, or
> something like #(#(1 3 5) #(1 3 5) #(1 3 5) ...)
> 
> Can someone enlighten me? It must be simple, but...

One way:

a := OrderedCollection new.
#(1 3 5) permutationsDo: [:each | a addLast: each copy ].
a

> P.S. If there is a more appropriate list for newbie
> please let me know. 

This is the correct list.

-- Duane



More information about the Squeak-dev mailing list