MathGroup Archive 2007

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

Search the Archive

Re: Permutations of a sequence - variation 2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76230] Re: [mg76175] Permutations of a sequence - variation 2
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Fri, 18 May 2007 06:10:17 -0400 (EDT)
  • References: <4712691.1179398561901.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

Clear[restrictedPermutations]
restrictedPermutations[x_List] :=
   Module[{one = x[[1]], n = Length@x, oneGoesTo,
     others = Permutations@Rest@x},
    oneGoesTo = Range[1, n - 1];
    Flatten[Outer[Insert[#1, one, #2] &, others, oneGoesTo, 1], 1]
    ];

restrictedPermutations@Range@4

{{1, 2, 3, 4}, {2, 1, 3, 4}, {2, 3, 1, 4}, {1, 2, 4, 3}, {2, 1, 4,
   3}, {2, 4, 1, 3}, {1, 3, 2, 4}, {3, 1, 2, 4}, {3, 2, 1, 4}, {1, 3,
   4, 2}, {3, 1, 4, 2}, {3, 4, 1, 2}, {1, 4, 2, 3}, {4, 1, 2, 3}, {4,
   2, 1, 3}, {1, 4, 3, 2}, {4, 1, 3, 2}, {4, 3, 1, 2}}

Bobby

On Thu, 17 May 2007 05:01:16 -0500, Virgil Stokes <vs at it.uu.se> wrote:

> Suppose I have a sequence:
>
>   {1,2,3,4,5}
>
> and I would like to generate all permutations of this sequence with th=
e
> constraint that the last element not be the same as the first.
> Thus,
>
>   {2,5,3,1,4}
>
> is acceptable; but,
>
>   {2,5,3,4,1}
>
> is not.
>
> Are there Mathematica commands that allow this to be done efficiently
> for a sequence {1,2,...,n}? Note, the solution of this problem can be
> used to solve the earlier problem that I posted on sequence permutatio=
ns.
>
> --V. Stokes
>
>



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Ellipse equation simplification on Mathematica:
  • Next by Date: Re: Where is the Mathematica
  • Previous by thread: Re: Permutations of a sequence - variation 2
  • Next by thread: All permutations of a sequence