title: php a and b players consecutive stones
body: <p>I have to find a php code to solve a math problem.</p>
  
  <p>This is the problem description: </p>
  
  <blockquote>
    <p>Players A and B are playing a new game of stones. There are <strong>N</strong> stones
    placed on the ground, forming a sequence. The stones are labeled <strong>from
    1 to N</strong>. Players A and B play in turns take exactly two consecutive stones
    on the ground until there are no consecutive stones on the ground.
    That is, each player can take stone <strong>i</strong> and stone <strong>i+1</strong>, where <strong>1≤i≤N−1</strong>. If
    the number of stone left is odd, A wins. Otherwise, B wins. Assume
    both A and B play optimally and A plays first, do you know who the
    winner is?</p>
    
    <p>The line has N stones and are indexed from 1 to N --> <strong>N  (1 ≤
    N ≤ 10 000 000)</strong></p>
    
    <p>If the number of stone left is odd, A wins. Otherwise, B wins.</p>
  </blockquote>
  
  <p>This is my code. It does work, but it is not correct.</p>
  
  <pre><code>        &lt;?php
  $nStones =  rand(1, 10000000);
  $string = ("i");
  $start = rand(1, 10000000);
  $length = 2;
  while($nStones &gt; 0) {
      substr( $nStones , $start [,  $length ]): string;
  }
  if ($nStones % 2 == 1) {
      echo "A";
  } else {
  echo "B";
  }
  ?&gt;
  </code></pre>
  
  <p>I think am missing the alternant subtraction of two consecutive stones by A &amp; B, while $nStones > 0. Furthermore, the problem description mentions an optima subtraction until there is only one stone left. Therefore I guess the stones move together to their closest stones (the gaps disappear and are replaced by the closest stones).</p>