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: [mg76260] Re: All permutations of a sequence
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Fri, 18 May 2007 06:25:55 -0400 (EDT)
  • References: <f2h8t7$v4$1@smc.vnet.net>

On May 17, 2:56 am, Virgil Stokes <v... at it.uu.se> wrote:
> 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

This will give the Length[list]!/2 permutations of 'list' in which
the first two elements are always in their orginal order.

halfperm[list_] := With[{a = list[[1]], b = list[[2]]},
Flatten[ Table[ Insert[#,a,i],{i,Position[#,b][[1,1]]} ]& /@
         Permutations@Rest@list, 1 ]]

h = halfperm@Range@8;
Sort@Join[h,Reverse/@h] === Permutations@Range@Length@h[[1]]

True



  • Prev by Date: Re: Mathematica 6.0 and MatrixManipulations
  • Next by Date: Re: All permutations of a sequence
  • Previous by thread: Re: All permutations of a sequence
  • Next by thread: Re: All permutations of a sequence