Re: [R] getting all circular arrangements without accounting for order

2018-03-30 Thread Ranjan Maitra
Jeff, Thanks! This one is much faster, no doubt! system.time(directionless_circular_permutations2(12)) user system elapsed 5.331 0.745 6.089 system.time(directionless_circular_permutations(12)) user system elapsed 173.659 0.890 174.946 However, from n = 13, things start bec

Re: [R] getting all circular arrangements without accounting for order

2018-03-30 Thread Jeff Newmiller
New function below is a bit faster due to more efficent memory handling. for-loop FTW! directionless_circular_permutations2 <- function( n ) { n1 <- n - 1L v <- seq.int( n1 ) ix <- combinations( n1, 2L ) jx <- permutations( n-3L, n-3L ) jxrows <- nrow( jx ) jxoffsets <- seq.int( jxro

Re: [R] getting all circular arrangements without accounting for order

2018-03-30 Thread Ranjan Maitra
Jeff, I wanted to let you know that your function is faster than generating the directional circular permutations and weeding. Here is the time for n = 10. I compared with just doing the permutations, there is no point in proceeding further with the weeding since it is slower at the start its

Re: [R] getting all circular arrangements without accounting for order

2018-03-30 Thread Berry, Charles
> On Mar 29, 2018, at 6:48 PM, Ranjan Maitra 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 pa

Re: [R] getting all circular arrangements without accounting for order

2018-03-30 Thread Ranjan Maitra
Thanks! It is not clear to me that the weeding step is straightforward to do efficiently. Comparing using rev appears to me to be an operation on the order of O(n^3). I guess one way would be to include everything with all 1's in the first slot (taking them out of consideration for future ope

Re: [R] getting all circular arrangements without accounting for order

2018-03-29 Thread Jeff Newmiller
I don't know if this is more efficient than enumerating with distinct directions and weeding... it seems kind of heavyweight to me: ### library(gtools) directionless_circular_permutations <- function( n ) { v <- seq.int( n-1 ) ix <- combinations( n-1, 2 ) jx <- permutations( n-3, n-3 )

Re: [R] getting all circular arrangements without accounting for order

2018-03-29 Thread Ranjan Maitra
Thanks! Yes, however, this seems a bit wasteful. Just wondering if there are other, more efficient options possible. Best wishes, Ranjan On Thu, 29 Mar 2018 22:20:19 -0400 Boris Steipe wrote: > If one is equal to the reverse of another, keep only one of the pair. > > B. > > > > > On Mar

Re: [R] getting all circular arrangements without accounting for order

2018-03-29 Thread Boris Steipe
If one is equal to the reverse of another, keep only one of the pair. B. > On Mar 29, 2018, at 9:48 PM, Ranjan Maitra 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

[R] getting all circular arrangements without accounting for order

2018-03-29 Thread Ranjan Maitra
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