[R] getting all circular arrangements without accounting for order

Berry, Charles ccberry at ucsd.edu
Fri Mar 30 18:46:53 CEST 2018



> On Mar 29, 2018, at 6:48 PM, Ranjan Maitra <maitra at email.com> wrote:
> 
> Dear friends,
> 
> I would like to get all possible arrangements of n objects listed 1:n on a circle.
> 
> Now this is easy to do in R. Keep the last spot fixed at n and fill in the rest using permuations(n-1, n-1) from the gtools package.
> 
> However, what if clockwise or counterclockwise arrangements are the same? I know that half of the above (n - 1)! arrangements are redundant.
> 
> Is there an easy way to list these (n-1)!/2 arrangements? 
> 

Well half of these arrangements will be of the form 

	`k, ... , j, n' 

and half will be of the form 

	`j, ...,  k, n'

So fix n in position n, select (k,j), and require that the first position is min(k,j) and position n-1 is max(k,j). 

There are choose(n-1,2) choices for {(k,j):k<j!=n}. Then you have (n-3)! ways to fill the rest. 

That gives (n-1)!/((n-3)! * 2!) * (n-3)! = (n-1)!/2 arrangements.

HTH,

Chuck



More information about the R-help mailing list