title: Select optimal pairings of elements
body: <p>I have following problem e.g:
  Given a bucket with symbols<br>
  <code>1 1 2 3 3 4</code><br>
  And book of recipes to create pairs e.g:<br>
  <code>12</code> <code>13</code> <code>24</code><br>
  Select from bucket optimal pairing, leaving as little as possible symbols in the bucket. So using the examplary values above the optimal pairing would be:<br>
  <code>13</code> <code>13</code> <code>24</code> Which would use all the symbols given.<br>
  Naive picking from the bucket could result in something like:<br>
  <code>12</code> <code>13</code> Leaving the <code>3</code> and <code>4</code> unmatched. <code>3</code> and <code>4</code> cannot be matched because the book does not contain a recipe for that particular connection</p>
  
  <p><strong>Notes:</strong><br>
  Real problem consits on average of: <strong>500</strong> elements in bucket in about <strong>30</strong>  kind of symbols.</p>
  
  <p>We've tried to implement the solution using the bruteforce algorithm, however I am afraid that even our grandchildren will not live long enough to see the result :).</p>
  
  <p>There is no limit to the size of recipe book, it could even have every possible in the bucket. Pair made of the same element twice is not allowed.</p>
  
  <p>The answer is not required to empty the bucket completely. Its just about getting the most pairs out of the bucket. Its okay to leave some in the bucket. It would be best to look for the optimal solution, however close approximation is also good enough.</p>
  
  <p>I will appreciate an answer that proposes/gives hint to an algorithm to solve the problem.</p>
  
  <p><strong>Examples:</strong><br>
  Bucket:<br>
  <code>1 1 2 2 2 2 3 3 3 4 5 6 7 8 8</code><br>
  Recipe book:<br>
  <code>12 34 15 68</code><br>
  Optimal result (one of possible):<br>
  <code>{1 2} {1 2} {3 4} {6 8}</code><br>
  Leftover:<br>
  <code>2</code> <code>2</code> <code>3</code> <code>3</code> <code>5</code> <code>7</code> <code>8</code></p>