Skip to content

Instantly share code, notes, and snippets.

@pradhuman-soni
Last active October 21, 2021 10:15
Show Gist options
  • Select an option

  • Save pradhuman-soni/482e22520f396d5562c4941e2eba7cb6 to your computer and use it in GitHub Desktop.

Select an option

Save pradhuman-soni/482e22520f396d5562c4941e2eba7cb6 to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/2021 printStairPaths
#include <iostream>
using namespace std;
void printStairPaths(int n, string psf){
if(n == 0) { //base case
cout << psf << endl; //print output string psf(path so far)
return;
}
for(int jumps = 1; jumps <= 3; jumps++) { // loop for making all possible jumps
if(n - jumps >= 0)
printStairPaths(n - jumps, psf + to_string(jumps)); // function call
}
}
int main(){
int n;
cin >> n;
printStairPaths(n, ""); // function call
}
def printStairPaths(ques, asf):
if ques == 0: # base case
print(asf)
return;
for i in range(1,4): # possible moves are 1, 2 and 3
if ques - i >= 0:
printStairPaths(ques - i, asf + str(i)) # recursive call
ques = int(input())
printStairPaths(ques, "");
#include <iostream>
using namespace std;
void printStairPaths(int n, string psf){
// write your code here
}
int main(){
int n;
cin >> n;
printStairPaths(n, ""); // function call
}
def printStairPaths(ques, asf):
# write your code here
ques = int(input())
printStairPaths(ques, "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment