Last active
October 21, 2021 10:17
-
-
Save pradhuman7d1/85664b2f7defad50cd5f3c59ad084bf0 to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/2021 printMazePaths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void printMazePaths(int sr, int sc, int dr, int dc, string psf){ | |
if(sr == dr && sc == dc) { // base case | |
cout << psf << endl; // output | |
return; | |
} | |
if(sr > dr || sc > dc) { // to prevent illegal moves | |
return; | |
} | |
printMazePaths(sr, sc + 1, dr, dc, psf + 'h'); // horizontal move | |
printMazePaths(sr + 1, sc, dr, dc, psf + 'v'); // vertical move | |
} | |
int main(){ | |
int n; | |
int m; | |
cin >> n >> m; | |
printMazePaths(0, 0, n - 1, m - 1, ""); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printMazePaths(sr, sc, dr, dc, asf): | |
if sr == dr and sc == dc: # base case | |
print(asf) | |
return | |
if sr > dr or sc > dc: # prevents illegal moves | |
return | |
# horizontal move | |
printMazePaths(sr, sc + 1, dr, dc, asf + 'h') | |
# vertical move | |
printMazePaths(sr + 1, sc, dr, dc, asf + 'v') | |
n = int(input()) | |
m = int(input()) | |
printMazePaths(0, 0, n - 1, m - 1, "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void printMazePaths(int sr, int sc, int dr, int dc, string psf){ | |
// write your code here | |
} | |
int main(){ | |
int n; | |
int m; | |
cin >> n >> m; | |
printMazePaths(0, 0, n - 1, m - 1, ""); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printMazePaths(sr, sc, dr, dc, asf): | |
# write your code here | |
n = int(input()) | |
m = int(input()) | |
printMazePaths(0, 0, n - 1, m - 1, "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment