title: My recursive function for finding the number of paths in a grid runs infinitely
body: <p>I'm working on a couple of Project Euler problems and want to test my solution. My recursive function never ends even with reachable base cases.</p>
  
  <p>in a 20x20 grid I am using x and y coordinates to navigate up and left to find the number of paths from (19,19) to (0,0). My base case is to return 1 when we reach (0,0). Otherwise I add the current count to the recursive call.</p>
  
  <p>Function:</p>
  
  <pre><code>private static int numPaths(int x, int y, int pathsFound)
  {
      if(x == 0 &amp;&amp; y == 0)
          return 1;
      else
      {
          if(x &gt; 0)
          {
              pathsFound += numPaths(x - 1, y, pathsFound);
          }
          if(y &gt; 0)
          {
              pathsFound += numPaths(x, y - 1, pathsFound);
          }
      }
      return pathsFound;
  }
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>int x = 19;
  int y = 19;
  System.out.println("Answer: " + numPaths(x, y, 0));
  </code></pre>
  
  <p>Is there a flaw in my recursive logic, or is just taking a very long time to compute? If you know the solution to this Euler problem, please do not post it.</p>
  
  <p><a href="https://projecteuler.net/problem=15" rel="nofollow">https://projecteuler.net/problem=15</a></p>