title: Can a Neural Network Find the i-th Permutation of a fixed size list?
body: <h2>Briefly</h2>
  
  <p>Can a neural network emulate factorial decomposition (or some other method) to provide a list permutation given the permutations unique index?</p>
  
  <h2>Application</h2>
  
  <p>I have a list of 10 things, and what they are is irrelevant. What I care about is that my 10 things can be placed into 3628800 (or 10!) unique orders, because then I can express any list order of my 10 things using an unsigned integer and factorial decomposition:</p>
  
  <pre><code>Order 0: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  Order 1: 0, 1, 2, 3, 4, 5, 6, 7, 9, 8
  Order ....
  Order 3628799: 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
  </code></pre>
  
  <p>This allows for the parallel distribution of analysis on different list orders of my 10 things.</p>
  
  <p>A common example being the travelling salesman problem: </p>
  
  <pre><code>1. I give 500 different computers each a range of unsigned integers:
     0    -&gt; 7257  for computer 0, 
     7257 -&gt; 14516 for computer 1, 
     etc.
  
  2. Each computer first calculates the list order from it's unsigned integer 
     index by using factorial decomposition.
     ie. Order 1 -&gt; 0, 1, 2, 3, 4, 5, 6, 7, 9, 8
  
  3. The distance between the cities placed in the order described is calculated.
  
  4. The shortest distances from each computer is collected, and the shortest 
     of those is taken. Leaving us with a single unsigned integer index that 
     describes the shortest possible permutation of cities.
  </code></pre>
  
  <p>The same process can be used to solve virtually any boundable error surface, given often far more than feasible computational power.</p>
  
  <h2>Recursive Algorithmic Solution</h2>
  
  <p>We can calculate the N-th permutation of any fixed size list (granted we will need large integer support for bigger lists) using factorial decomposition (<a href="https://stackoverflow.com/questions/7918806/finding-n-th-permutation-without-computing-others">outlined here in php</a>), and provided here in javascript for clarity:</p>
  
  <pre><code>function ithPermutationOfNElements (n, i)
  {
     var j, k = 0;
     var fact = [];
     var perm = [];
  
     // compute factorial numbers
     fact[k] = 1;
     while (++k &lt; n)
        fact[k] = fact[k - 1] * k;
  
     // compute factorial code
     for (k = 0; k &lt; n; ++k)
     {
        perm[k] = Math.floor(i / fact[n - 1 - k]);
        i = i % fact[n - 1 - k];
     }
  
     // readjust values to obtain the permutation
     // start from the end and check if preceding values are lower
     for (k = n - 1; k &gt; 0; --k)
        for (j = k - 1; j &gt;= 0; --j)
           if (perm[j] &lt;= perm[k])
              perm[k]++;
  
     return perm;
  }
  console.log(ithPermutationOfNElements(4, 23)); // [ 3, 2, 1, 0 ]
  </code></pre>
  
  <h2>Neural Network Solution?</h2>
  
  <p>Can any neural network architecture &amp; training combination emulate this function given i as it's only input neuron and n output neurons representing each element of the permutation?</p>