title: Count paths in a matrix
body: <p>This is a question from homework, that I got stuck with, and I'll be happy if someone could direct me.</p>
  
  <p>A legal path is defined, by statring at the first cell (row 0 collumn 0), and countinue to the next step by adding the first and the second digits of the number in the cell, untill reaching the last cell (row n collumn n).</p>
  
  <p>For example:
  If in cell [2][3] there is the number 15, then the next move can be:
  +1 in rows and +5 in collumns to [3][8]
  or
  +5 in row and +1 in collumns to [7][4]</p>
  
  <p>The method should return how many legal paths are there.</p>
  
  <p>I'm trying to use a backtracing recursive method for this problem, and I can't use any loops or any other method but overloading methods.</p>
  
  <p>Here is the code I came up with so far:</p>
  
  <pre><code>public static int countPaths (int[][] mat)
  {
      return countPaths(mat,0,0);
  }
  
  private static int countPaths(int[][] mat, int col, int row)
  {
  
  
      if ((col==mat.length-1 &amp;&amp; row==mat[0].length-1 )  {
          return 1;
      }    
      return countPaths(mat,mat[col][row]/10+col,mat[col][row]%10+row) + countPaths(mat,mat[col][row]%10-col,mat[col][row]/10-row);
  
  } 
  </code></pre>
  
  <p>Thanks for any help !</p>