Skip to content

Instantly share code, notes, and snippets.

@pradhuman7d1
Last active October 21, 2021 10:17
Show Gist options
  • Save pradhuman7d1/85664b2f7defad50cd5f3c59ad084bf0 to your computer and use it in GitHub Desktop.
Save pradhuman7d1/85664b2f7defad50cd5f3c59ad084bf0 to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/2021 printMazePaths
#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, "");
}
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, "")
#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, "");
}
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