title: Finding minimal distance between unsorted and sorted lists
body: <p>Let A be a list and S a sorted list of the same elements. Assume all elements are different. How do I find a minimal set of "moves" (<code>move X before Y (or end)</code>) that turns A into S?</p>
  
  <p>Examples:</p>
  
  <pre><code>A = [8,1,2,3]
  S = [1,2,3,8]
  
  A =&gt; S requires one move: 
     move 8 before end
  
  A = [9,1,2,3,0]
  S = [0,1,2,3,9]
  
  A =&gt; S requires two moves:
     move 9 before 0
     move 0 before 1
  </code></pre>
  
  <p>I prefer javascript or python, but any language will do.</p>