[Squeak] Newbie permutations

Scott Wallace scott.wallace at squeakland.org
Tue Apr 9 07:12:28 UTC 2002


Michael,

There's probably at least one cool way using streams to do this, and 
at least one other cool way using #inject:into:; but the following 
naive approach works painlessly:

Foo _ OrderedCollection new.
#(1 3 5) permutationsDo: [:each | Foo add: each].

HTH,

   -- Scott


At 11:52 PM -0700 4/8/02, Michael Grant wrote:
>Hello everyone.
>
>I don't know if this is the correct forum but I can
>find no other mailing list so here goes (at 3:00am):
>
>I need a Smalltalk 'AHA!' moment.
>
>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...
>
>Thank you,
>Michael Grant
>
>P.S. If there is a more appropriate list for newbie
>please let me know.
>
>
>
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Tax Center - online filing with TurboTax
>http://taxes.yahoo.com/




More information about the Squeak-dev mailing list