[R] Find cyclically identical binary sequences

2009-05-05 Thread Michael Kubovy
Dear R-helpers,

I need to generate all the binary sequences of length n (here n = 8)  
that start with 1 and have no fewer than two of each digit, and are  
not cyclic permutations of each other. Here is what I have done:

len - 8
df - as.data.frame(numeric(2^(len - 1)) %o% numeric(len))
require(partitions)
for (i in 1:2^(len - 1)) df[i, ] - binary(i, dim = len)[[1]]
df - df[which(df[, 1] == 1), ]
df - df[which(rowSums(df)  1), ]
df - df[which(rowSums(df)  len - 1), ]

The following are cyclic permutations of each other:
df[which(rowSums(df) == 3), ][c(2, 15), ]

I would like to retain the larger of the two (if considered a binary  
number).

Can someone suggest an algorithm?

Thanks,
Michael

_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Find cyclically identical binary sequences (corrected)

2009-05-05 Thread Michael Kubovy

Dear R-helpers,

I need to generate all the binary sequences of length n (here n = 8)
that start with 1 and have no fewer than two of each digit, and are
not cyclic permutations of each other. Here is what I have done:

len - 8
df - as.data.frame(numeric(2^(len - 1)) %o% numeric(len))
require(wle)
for (i in 1:2^(len - 1)) df[i, ] - binary(i, dim = len)[[1]]
df - df[which(df[, 1] == 1), ]
df - df[which(rowSums(df)  1), ]
df - df[which(rowSums(df)  len - 1), ]

The following are cyclic permutations of each other:
df[which(rowSums(df) == 3), ][c(2, 15), ]

I would like to retain the larger of the two (if considered a binary
number).

Can someone suggest an algorithm?

Thanks,
Michael

_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
   McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.