title: Card Algorithm Game
body: <p>I was playing with the following problem and have a brute force approach but could not come up with a nice solution. The problem is as follows:</p>
  
  <p>There are 2*N cards. You and your opponent split them up (N cards to you and N to them). You know exactly what cards they have and what order they will play them in. </p>
  
  <p>The rules of the game are as follows: For the first N/2 rounds, the person with the highest card wins and for last N/2 rounds, the person with the lowest card wins. </p>
  
  <p>Given these rules and the order your opponents plays there cards, what is the maximum amount of wins you can get. </p>
  
  <p>Example: </p>
  
  <p>You have the cards: 2, 5, 6, 7.
  Your opponent has the cards: 1, 8, 4, 3 and plays them in that order.</p>
  
  <p>The maximum score you can get is 2 since you play a 7 to their 1, lose the 2nd and 3rd round, and then play 2 in the last round to win. </p>
  
  <p>My ideas: split your cards into two piles, your larger numbered and lower numbered ones. Then figure out an optimum matching up. </p>
  
  <p>Pseudocode/algorithmic ideas would be greatly appreciated. </p>
  
  <p>EDITS: There are a total of N rounds. The first N/2 rounds: the higher card wins. The last N/2 rounds: the lower card wins. N must be even. </p>