On 31 December 2017 at 04:00, Andy Burnett <andy.burn...@knowinnovation.com> wrote:
> I suspect I am missing something very obvious, in which case could some > kind soul put me straight? > > I have the following code > > col := OrderedCollection new. > (1 to: 9) permutationsDo: [ :each | col add: (each )]. > > I thought this would give me a collection containing all the permutations. > However, what actually happens is that each of the arrays has been > 'magically' sorted back into numerical order. If I change the code to read > > col := OrderedCollection new. > (1 to: 9) permutationsDo: [ :each | col add: (each asOrderedCollection )]. > > Then the permutations are retained. Is this how it is supposed to work? > Or, am I doing something wrong? > > Cheers > Andy > Its not so much that your first example sorted the permutations, but that the collection contained only one permutation. I've swapped the order of your examples and downsized them to the simplest case to observe. Something seems broken. It works as expected if the "copy" is uncommented. Transcript clear. oc1 := OrderedCollection new. oc2 := OrderedCollection new. Transcript crShow:'a---'. (1 to: 3) permutationsDo: [ :each | Transcript crShow: each. oc1 add: each asOrderedCollection]. Transcript crShow:'b---'. (1 to: 3) permutationsDo: [ :each | Transcript crShow: each. oc2 add: each "copy"]. Transcript crShow:'c---'. Transcript crShow: { oc1 asSet size. oc2 asSet size}. Transcript crShow:'d---'. oc2 do: [ :x | Transcript crShow: x ]. ==> a--- #(1 2 3) #(1 3 2) #(2 1 3) #(2 3 1) #(3 2 1) #(3 1 2) b--- #(1 2 3) #(1 3 2) #(2 1 3) #(2 3 1) #(3 2 1) #(3 1 2) c--- #(6 1) d--- #(1 2 3) #(1 2 3) #(1 2 3) #(1 2 3) #(1 2 3) #(1 2 3) cheers -ben