You can use the function permutation from the e1071 package, then library(e1071)
multisetperm <- function(multiset) { unique(apply(matrix(multiset[permutations(length(multiset))], ncol=length(multiset)), 1, paste, sep="", collapse="")) } multisetperm(c("0", "0", "1", "2", "2")) > The output would look something like this: > > 00122 > 01220 > 01210 > 20201 > 10202 > 12200 > etc... > > The Java algorithm you cited does not look any more clever or less wasteful than this. ______________________________________________ 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.