MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: All permutations of a sequence

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76323] Re: All permutations of a sequence
  • From: "Sem" <sarner2006-sem at yahoo.it>
  • Date: Sat, 19 May 2007 04:51:56 -0400 (EDT)
  • References: <f2h8t7$v4$1@smc.vnet.net>

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
> 



  • Prev by Date: Re: Residue Function
  • Next by Date: Re: Re: 6.0 not seeing style sheets in $InstallationDirectory/SystemFiles/FrontEnd/StyleSheets
  • Previous by thread: Re: All permutations of a sequence
  • Next by thread: Re: All permutations of a sequence