title: Sorting algorithm to implement highest total combinations
body: <p>I'm interested in learning what algorithm would be best suited to solve the following problem. Here's the criteria. </p>
  
  <p>I have a list of players. Each player has three attributes. </p>
  
  <ul>
  <li>Team</li>
  <li>Value</li>
  <li>Position</li>
  </ul>
  
  <p>Each team has roughly 20 players. Let's say we're talking baseball here and the positions are <code>1B</code>, <code>2B</code>, <code>3B</code>, <code>SS</code>, <code>C</code>, <code>OF</code>.</p>
  
  <p>What I'm interested in doing is sorting for the top <code>N</code> combinations, where <code>N &gt; 0</code> of the highest combined value for <code>4</code> team mates.</p>
  
  <p>So each combination of <code>4 players</code> has to be on the same team. Each combination of <code>4 players</code> should have a higher total combined <code>Value</code> then every subsequent combination.</p>
  
  <p>The one restriction is that every position can be used only once per combination, except for <code>OF</code> which can be used up to three times in one combination of 4 players.</p>
  
  <p>So in the following pool of made up players, I'll show the top 2 combinations:</p>
  
  <pre><code>Team Toronto
  Player 1, SS, 1.0
  Player 2, 1B, 1.0
  Player 3, 1B, 2.0
  Player 4, 2B, 2.0
  Player 5, 3B, 4.0
  Player 6, 3B, 3.0
  Player 7, C, 4.0
  Player 8, OF, 1.0
  Player 9, OF, 2.0
  Player 10, OF, 5.0
  Player 11, OF, 6.0
  
  Team Washington
  Team Toronto
  Player 1, SS, 3.0
  Player 2, 1B, 2.0
  Player 3, 1B, 1.0
  Player 4, 2B, 2.0
  Player 5, 3B, 2.0
  Player 6, 3B, 3.0
  Player 7, C, 7.0
  Player 8, OF, 1.0
  Player 9, OF, 2.0
  Player 10, OF, 2.0
  Player 11, OF, 3.0
  </code></pre>
  
  <p>The highest projected combo would be</p>
  
  <pre><code>Team Toronto: 
     * Player 11
     * Player 10
     * Player 7
     * Player 5 
  </code></pre>
  
  <p>total value of <code>19.0</code></p>
  
  <p>The second highest projected combo would also be Team Toronto with </p>
  
  <pre><code>* Player 11
  * Player 10
  * Player 7
  * Player 6 
  </code></pre>
  
  <p>with a total of <code>18.0</code></p>
  
  <p>Team Washington's highest combo is Player 1, Player 6, Player 7 and Player 11, and their value is only <code>16.0</code> so they wouldn't show up until later in the sort.</p>
  
  <p>What's the best algorithm to handle this in an efficient fashion if say I'm dealing with a pool of 500 players daily (distributed over 10 or more teams)?</p>