Re: All permutations of a sequence
- To: mathgroup at smc.vnet.net
- Subject: [mg76333] Re: All permutations of a sequence
- From: "Sem" <sarner2006-sem at yahoo.it>
- Date: Sun, 20 May 2007 02:20:04 -0400 (EDT)
- References: <f2h8t7$v4$1@smc.vnet.net> <f2mful$mm7$1@smc.vnet.net>
Sorry, the loading of the package 'Combinatorica' isn't necessary for the function. "Sem" > Hi Virgil, > > the above code produces all the permutations of a list, except those that > reverse their ordering. > The function is recursive but I suppose that an iterative algorithm can be > wrote easily, i.e. for large list. > > << DiscreteMath`Combinatorica` > > NotReversingPermutations[l_List] := {l} /; Length[l] <= 2 > > NotReversingPermutations[l_List] := > Module[ > {e = Last[l], n = Length[l], r}, > r = Table[Insert[#, e, -i], {i, 1, n}] & /@ > NotReversingPermutations[Drop[l, -1]]; > Flatten[r, 1] > ]; > > HTH > Regards, > > Sem > >>"Virgil Stokes" >>I would like to get all unique permutations of a sequence (e.g. >> {1,2,3,4,5,6,7,8,9,10,11,12,13}) with the constraint that all sequences >> that have an opposite ordering are not included (e.g. {13, 12, >> 11,10,9,8,6,5,4,3,2,1}) would not be included. >> >> Are there some Mathematica commands that can be used to efficiently >> generate these permutations? >> >> --V. Stokes >> > >