Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg76261] Re: Permutations of a sequence - variation 2
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Fri, 18 May 2007 06:26:59 -0400 (EDT)

On 5/17/07 at 6:01 AM, vs at it.uu.se (Virgil Stokes) wrote:

>Suppose I have a sequence:

>{1,2,3,4,5}

>and I would like to generate all permutations of this sequence with
>the 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 permutations.

The brute force way of generating all possible permutations and
deleting those you don't want is fairly easy to do, i.e., for n=3

In[5]:= DeleteCases[Permutations@Range[3], {__, 1}]

Out[5]= {{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {3, 1, 2}}

And if n isn't too large, I suspect this likely to be the
quickest, most efficient way.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: All permutations of a sequence
  • Next by Date: Re: Using Select
  • Previous by thread: Permutations of a sequence - variation 2
  • Next by thread: Re: Permutations of a sequence - variation 2