On Tue, 5 Jan 2010, Randal L. Schwartz wrote:

>>>>>> "Levente" == Levente Uzonyi <[email protected]> writes:
>
> Levente> On Tue, 5 Jan 2010, John Toohey wrote:
>>> But this doesn't get 1-1, 2-2 or 3-3. I had tried something like that use
>>> #reverse on each combination, but #combinations does not generate
>>> -duplicates- from the number sequences.
>
> Levente> I guess you are looking for this:
> Levente> allPairsFromCollectionDo := [ :collection :block |
> Levente>      | o |
> Levente>      o := OrderedCollection newFrom: collection.
> Levente>      o size timesRepeat: [
> Levente>              o with: collection do: block.
> Levente>              o add: o removeFirst ] ].
>
> Or more simply:
>
> aCollection do: [:x | aCollection do: [:y | "use x and y"]].

Nice, it's funny that I didn't find this simple solution. And it's O(n^2) 
instead of O(n^3) like mine (because OrderedCollection is implemented 
such a dumb way).


Levente

>
> Unless I'm misunderstanding the problem.
>
> Which is neither combinations nor permutations, but so far is the only thing
> that fits all the bizarre conditions.
>
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <[email protected]> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
>

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to