title: Recursive Algorithm for Tournament Brackets
body: <p>I am creating a tournament bracket creation script, and I am getting stuck with tournaments with the number of players Non - Power of 2.  For instance, it is currently working great for 2, 4, 8, 16, 32,... etc.  But for 3, 5, 6, 7... I am stumped!</p>
  
  <p><strong>Here is what I have so far:</strong></p>
  
  <pre><code>$numrows = 8; // Currently for Testing.
  draw_bracket($numrows);
  
  function draw_bracket($numplayers)
  {
      draw_series_container();
      draw_bracket_layer($numplayers, 0);
      draw_series_container_end();
  }
  
  /* RECURSION, YO! */
  function draw_bracket_layer($numplayers, $layer)
  {
      $levels = floor(log($numplayers, 2));
      if ($layer == $levels - 1)
      {
          draw_player_box();
          draw_player_box();
      }
      else
      {
          draw_series_container();
              draw_bracket_layer($numplayers, $layer + 1);
          draw_series_container_end();
  
          draw_series_container();
              draw_bracket_layer($numplayers, $layer + 1);
          draw_series_container_end();
      }
  }
  </code></pre>
  
  <p>I am assuming we need more 'base cases'.  Or perhaps more if statements for these off cases.</p>
  
  <p>The functions draw_series_container() and draw_player_box are just filled with HTML code.  I can show them if we need to.  </p>
  
  <p>Could someone start me out with a bracket with 5 or 6 people?</p>
  
  <p>Thanks!</p>