So, I need an algorithm to generate all permutations of the list of numbers excluding cyclic rotations (for example, [1,2,3] == [2,3,1] == [3,1,2]).
If the sequence has at least 1 unique number, it is fairly straightforward, remove this unique number, generate all the permutations of the remaining numbers (but with a slight modification of the "standard" permutation algorithm) and add a unique number in front.
To create permutations, I found that it was necessary to change the permutation code to:
def permutations(done, options)
permuts = []
seen = []
for each o in options
if o not in seen
seen.add(o)
permuts += permutations(done+o, options.remove(o))
return permuts
Only using each unique number in the parameters once means that you do not get 322 twice.
This algorithm still outputs rotations when there are no unique elements, for example. for [1,1,2,2] it outputs [1,1,2,2], [1,2,2,1] and [1,2,1,2], and the first two are cyclic rotations.
So, is there an efficient algorithm that would allow me to generate all permutations without having to go through after that to remove cyclic rotations?
If not, what is the most effective way to remove cyclic rotations?
NOTE : this is not using Python, but rather C ++.