Jan. 5, 2010
5:16 p.m.
On Jan 5, 2010, at 5:19 32PM, John Toohey wrote:
Hi, I'm trying to generate the permutations of a sequence of numbers. I've found # permutationsDo: aBlock, but this generated the permutation of the entire sequence. I want to do it in groups of 2. The #combinations: anInteger atATimeDo: aBlock method does what I need for combinations, but I cannot find the equivalent for permutations. Does something like this exist in the standard library, or in an external package.
-- -JT
How about: #(1 2 3 4) combinations: 2 atATimeDo: [:array | array permutationsDo: [:each | Transcript show: each printString; cr]] ? Cheers, Henry