title: Finding n-th permutation without computing others
body: <p>Given an array of N elements representing the permutation atoms, is there an algorithm like that:</p>
  
  <pre><code>function getNthPermutation( $atoms, $permutation_index, $size )
  </code></pre>
  
  <p>where <code>$atoms</code> is the array of elements, <code>$permutation_index</code> is the index of the permutation and <code>$size</code> is the size of the permutation.</p>
  
  <p>For instance:</p>
  
  <pre><code>$atoms = array( 'A', 'B', 'C' );
  // getting third permutation of 2 elements
  $perm = getNthPermutation( $atoms, 3, 2 );
  
  echo implode( ', ', $perm )."\n";
  </code></pre>
  
  <p>Would print:</p>
  
  <pre><code>B, A
  </code></pre>
  
  <p>Without computing every permutation until $permutation_index ?</p>
  
  <p>I heard something about factoradic permutations, but every implementation i've found gives as result a permutation with the same size of V, which is not my case.</p>
  
  <p>Thanks.</p>