So I need an algorithm to generate all permutations of a list of numbers excluding cyclic rotations (e.g. [1,2,3] == [2,3,1] == [3,1,2]).
When there is at least 1 unique number in the sequence it is fairly straight forward, take out that unique number, generate all permutations of the remaining numbers (but with a small modification to the 'standard' permutations algorithm) and add the unique number to the front.
For generating the permutations I've found that it's necessary to change the permutations 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 options once means that you don't get 322 twice.
This algorithm still outputs rotations when there are no unique elements, e.g. for [1,1,2,2] it would output [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 the permutations without having to go through afterwards to remove cyclic rotations?
If not, what would be the most efficient way to remove cyclic rotations?
NOTE: this is not using Python, but rather C++.