title: Identify this Algorithm: Slots and Pegs
body: <p>I have a number of slots and pegs arranged in a straight line. The pegs can be moved and need to be moved to a slot each. A slot can be left empty only if all pegs are taken. When a peg is moved, it is not allowed to go past another peg. In other words the order of the pegs must be maintained. Preferably, the total distance moved by all pegs should be kept at a minimum. As far as possible, a peg should be placed in the nearest available slot.</p>
  
  <p>All I want to know is: What field of mathematics deals with such a problem? What are the names of any well known algorithms which deal with similar problems? I am looking for Google fodder. Some keywords.</p>
  
  <pre><code>+--oooo-+--+---+---o--+------+--+-ooo+o-+-------o--+-----o-o-+-o
  
  + - Slots
  o - Pegs
  </code></pre>
  
  <p><br>
  <strong>EDIT:</strong> I think that this visualization makes more sense. They are two separate tracks that need to line up.</p>
  
  <pre><code>Slots: +-------+--+---+------+------+--+----+--+----------+---------+--
  Pegs:  ---oooo------------o--------------ooo-o---------o--------o-o---o
  </code></pre>
  
  <p><strong>EDIT:</strong> Just want to make it clear that the number of slots can be greater than, less than or equal to the number of pegs.</p>