title: Generating all permutations excluding cyclic rotations
body: <p></p>
  
  <p>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]).</p>
  
  <p>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.</p>
  
  <p>For generating the permutations I've found that it's necessary to change the permutations code to:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Only using each unique number in options once means that you don't get 322 twice.</p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>If not, what would be the most efficient way to remove cyclic rotations?</p>
  
  <p><strong>NOTE</strong>: this is <em>not</em> using Python, but rather C++.</p>