title: Little changes in the given algorithm
body: <p>It's about changing a maze algorithm.</p>
  
  <p>What I mean by that? We got a 2-dimensional array filled with 0 and 1 where 0 stands for "not possible to pass" and 1 for "possible to pass".
  An that algorithm finds its way from x to y (also known example: cat to mouse).
  And this exactly is what the following algorithm is doing.</p>
  
  <p>As input we got:</p>
  
  <pre><code>{1, 0, 0,},
  {1, 1, 0},
  {0, 1, 1} };
  </code></pre>
  
  <p>And the output:</p>
  
  <pre><code>(0,0) // ressembles the coordinates of the 1 in top left corner 
  (1,0) // ressembles the 1 under the first 1 I just explained
  (1,1) // ...
  (2,1)
  (2,2)
  </code></pre>
  
  <p>I want change some little things:</p>
  
  <ol>
  <li>Change the starting and end position (this algorithm starts in top left and ends in bottom right) - I want mine to start in bottom left and end top right.</li>
  <li>This algorithm can only move down and right - I want only move up and right.</li>
  </ol>
  
  <p>What changes need to be done, I'm pretty sure but I don't know how to code that:
  For 1.) the problem seems to be:</p>
  
  <pre><code>public List&lt;Coordinate&gt; solve() {
          return getMazePath(0, 0, new Stack&lt;Coordinate&gt;());
      }
  </code></pre>
  
  <p>Somehow, I need to do 0-1 with the second zero but how if I haven't access to x and y declaration? I really believe 0-1 would make me start at bottom left instead of top left, is that right?</p>
  
  <p>For 2.) changes for the column, also know as y need to be done.
  Instead of +1 it requires -1, is that right?</p>
  
  <p>Sorry for that wall of text, I really tried to keep it short but I seem to have failed :P
  Anyway I hope someone will read this^^</p>
  
  <p>Algorithm WITHOUT the changes:</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.*;
  
  final class Coordinate {
      private final int x;
      private final int y;
  
      public Coordinate(int x, int y) {
          this.x = x; 
          this.y = y;
      }
  
      public int getX() {
          return x;
      }
  
      public int getY() {
          return y;
      }
  }
  
  public class Alg {
  
      private final int[][] maze;
  
      public Alg(int[][] maze) {
          if (maze == null) {
              throw new NullPointerException("The input maze cannot be null");
          }
          if (maze.length == 0) {
              throw new IllegalArgumentException("The size of maze should be greater than 0");
          }
  
          this.maze = maze;
      }
  
      public List&lt;Coordinate&gt; solve() {
          return getMazePath(0, 0, new Stack&lt;Coordinate&gt;());
      }
  
      private List&lt;Coordinate&gt; getMazePath(int row, int col, Stack&lt;Coordinate&gt; stack) {
          assert stack != null;
  
          stack.add(new Coordinate(row, col));
  
          if ((row == maze.length - 1) &amp;&amp; (col == maze[0].length - 1)) {
              Coordinate[] coordinateArray = stack.toArray(new Coordinate[stack.size()]);
              return Arrays.asList(coordinateArray);
          }
  
          for (int j = col; j &lt; maze[row].length; j++) {
  
              if ((j + 1) &lt; maze[row].length &amp;&amp; maze[row][j + 1] == 1) {
                  return getMazePath(row, j + 1, stack);
              }
  
              if ((row + 1) &lt; maze.length &amp;&amp; maze[row + 1][col] == 1) {
                  return getMazePath(row + 1, col, stack);
              }
          }
  
          return Collections.emptyList();
      }
  
  
      public static void main(String[] args) {
          int[][] m = {  {1, 0, 0,},
                         {1, 1, 0},
                         {0, 1, 1} };
  
          Alg maze = new Alg(m);
  
          for (Coordinate coord :  maze.solve()) {
              System.out.println("("+coord.getX() + "," + coord.getY()+")");
          }
      }
  }
  </code></pre>