![the permute class has five private data members the permute class has five private data members](https://www.reuters.com/resizer/YEuIfAwCpynBLKr20auoAxqJojg=/728x381/smart/filters:quality(80)/cloudfront-us-east-2.images.arcpublishing.com/reuters/OHFHEBC3NRPF5DRFDMJCROTBE4.jpg)
If no element was inserted in max_attempts attempts, start all over again from scratch.If possible then insert e into b at position p, otherwise increase attempts and try again Select a random position p from 0 to b.size(), with 0 meaning before the first element and b.size() meaning after the last element, and check if it is possible to insert e at this position without causing a repeat.Randomly permute the list without the non-repeating constraint in order to get a random order in which to insert the elements.One approach is to build the sequence one element at at time by adding new elements at random positions, instead of choosing each element in order. I thought this would be an interesting problem and will add a bounty for it when allowed.Ī sample long sequence is available here. I do not know C++ that well, but would be interested in trying to utilize that through Rcpp to get a solution that works. Everything tried is too slow and also not very good at finding non-repeated elements. I have tried using R to solve this problem. The total number of each element looks something like this: A B C D E F G H I J K L M N O P Q R ZĦ537 3156 1736 8 11 222 484 242 338 59 Sequences may be up to 50,000 elements long. The randomly sampled sequences need to have the same proportion of elements as the original sequence but also have no repeated elements. I need to permute (randomly shuffle) this sequence 10000 times.The original sequence never has any repeated elements. ".IDPGCGDCIDPGCGCDIDPGCGDCPGCIDPFJAIAHAHAHABAHAHABKPGCPGCGCECDGCPGCGCIDIPFCPGEPAJIAEPGCECJIPGCGPGCGCGADPDJDPGCPCPGCDIPEPGCJAJMAHZABAHAHAHABHAHBKRZALOBKAHABKLAHAHAHABKLKLAKLBKABABLAHAHABKBKLOKIABKLAHAHABKLABKALKABKLKAHBAKLABKBAHABLALKABABJLKAKLKHABKCRAHAKLKAKLABKLKLBKAHAKLKECECGDCGECGEDGCDGDGECECEGDCACACAHABABCDCHAHBKCQGCGCQCQGCQCGCACACBKCDCAHACQGCPGCDACAPCQAHAHBKACHAHAHBABCGCGCAHAHAMHMABAHAKLABKCPCFCABCQCQGCGCABHAHANBKQAHAHANANABKLABAKLPCGCGCPCAHABAHAHAHAHANBKALCQCGCECAHABANAHBKAKBKAHABAHBKALBHAHABKLKCPCECALCGCAKPHBAHAHAHAHAHAHABAHAHBKAMJABAHBAHAHBKALKABKPCQBANAHANHABKHBALAHALAHANBANBHABKAHANHAHABKAHAHAHAHAMANIAHABANHABABKBKLHLKLBKLKBKBKBALAHAKLBKLBHKBABHAMABKZAHAHABLKAHABAKABKOKHAKAHAHBKAHAHAHABKLHAHBKAHABKLAHAHABKAIAIAHABKLBAIAIKLKLAHAH." It is still the case that any solution in R is far too slow for my needs.įor a sequence where every letter is a separate element, e.g.
#The permute class has five private data members how to#
A year ago I asked a question in the R forum regarding how to permute a sequence 1000s of times but never allowing for repeated elements.