title: Java algorithm assistance
body: <p>So my current task is to create an algorithm that shifts the piles of beepers in a row 1 space to the right. I think I have a good start, I wrote the code to pick up a pile of beepers, move one to the right, and drop those beepers:</p>
  
  <pre><code>    public static void shift(Athlete arg)
  {
      int count = 0;
  
      while(!arg.nextToABeeper()) //the robot will move until it finds a beeper
      {
          arg.move();
      }
  
      while(arg.nextToABeeper()) //the robot will pick up the beepers in the pile, and keep a tab of them
      {
          arg.pickBeeper();
          count++;
      }
      arg.move();
      while(count &gt; 0) //after moving 1 space to the right, it drops the beepers
      {
          arg.putBeeper();
          count--;
      }
      shift(arg);
  }
  </code></pre>
  
  <p>The row of beepers sometimes has gaps in between the beepers, in which case this code works well, but if beeper piles are adjacent, the robot ends up dumping the first pile onto the second pile and I don't know how to pick up the second pile's beepers because now the second pile's beepers are comprised of the first and the second piles beepers and I don't know how to pick up only the second piles beepers.</p>
  
  <p>Rohit jain gave me the idea to start at the end of the row and go backwards. though I don't think this is how the problem is intended to be solved, it is a solution nonetheless.
  because there are gaps between the beepers, getting to the end of the row is actually more difficult then one might think. here's what I ended up doing.</p>
  
  <pre><code>    public static void goToEnd(Athlete arg)
  {
      while(!arg.nextToABeeper())
      {
          arg.move();
      }
      while(arg.nextToABeeper())
      {
          arg.move();
      }
      if(!arg.nextToABeeper())
      {
          arg.move();
          if(!arg.nextToABeeper())
          {
              arg.turnAround();
              arg.move();
          }
          else
          {
              while(arg.nextToABeeper())
              {
                  arg.move();
              }
              arg.turnAround();
          }
      }       
  }
  </code></pre>