title: Check for poker straight
body: <p>I have managed to create an algorithm to check the rank of a poker hand. It works 100% correctly, but it's very slow. I've been analysing the code, and the check straight function is one of the slowest parts of it. </p>
  
  <p>So my question is, is there a better way of calculating whether a hand make a straight?</p>
  
  <p>Here is some details: </p>
  
  <p>7 cards, 2 from holder, 5 from board. A can be high or low. </p>
  
  <p>Each card is assigned a value: 
      2 = 2
      3 = 3
      ..
      9 = 9
      T = 10
      J = 11
      Q = 12
      K = 13
      A = 14</p>
  
  <p>The script has an array of all 7 cards:</p>
  
  <pre><code>$cards = array(12,5,6,7,4,11,3);
  </code></pre>
  
  <p>So now I need to be able to sort this into an array where it:</p>
  
  <ul>
  <li>discards duplicates</li>
  <li>orders the card from lowest to highest</li>
  <li>only returns 5 consecutive cards I.e. (3,4,5,6,7)</li>
  </ul>
  
  <p>It needs to be fast; loops and iterations are very costly. This is what I currently use and when it tries to analyse say 15000 hands, it takes its toll on the script.</p>
  
  <p>For the above, I used:</p>
  
  <ul>
  <li>discard duplicates (use array_unique)</li>
  <li>order cards from lowest to highest (use sort())</li>
  <li>only return 5 consecutive cards (use a for loop to check the values of cards)</li>
  </ul>
  
  <p>Does anyone have any examples of how I could improve on this? Maybe even in another language that I could perhaps look at and see how it's done?</p>