public class PrintMazePaths {
public static void main(String[] args) throws Exception {
printMazePaths(0, 0, 2, 2, "");
}
// sr - source row
// sc - source column
// dr - destination row
// dc - destination column
public static void printMazePaths(int sr, int sc, int dr, int dc, String psf) {
if (sr == dr && sc == dc) {
System.out.println(psf);
return;
}
if (sr < dr)
printMazePaths(sr + 1, sc, dr, dc, psf + "v");
if (sc < dc)
printMazePaths(sr, sc + 1, dr, dc, psf + "h");
}
}
No comments:
Post a Comment