Closed RobinHankin closed 1 year ago
Spent a bit of time trying to leverage the partitions
package and came up with this:
do.call("c",apply(matrix(c(6,22,55,33,7)[perms(5)],nrow=5),2,as.cycle))
[1] (6,22,55,33,7) (6,22,55,7,33) (6,22,33,55,7) (6,22,33,7,55) (6,22,7,55,33)
[6] (6,22,7,33,55) (6,55,22,33,7) (6,55,22,7,33) (6,55,33,22,7) (6,55,33,7,22)
[11] (6,55,7,22,33) (6,55,7,33,22) (6,33,22,55,7) (6,33,22,7,55) (6,33,55,22,7)
[snip]
(this is not desired functionality because it includes permutations that are not a single cycle). The partitions
package does not have a way to generate all cyclic permutations of $\lbrace 1,2,\ldots,n\rbrace$. I will raise an issue in the partitions repo for this.
repopening, df16a5b should have closed issue #44, not issue #42
Function
allcyc()
generates all cycles of the set $\left\lbrace 1,2,\ldots,n\right\rbrace$. But it would be nice to generalize this to give all cycles of any set. Look: