Last active
October 21, 2021 10:15
-
-
Save pradhuman-soni/482e22520f396d5562c4941e2eba7cb6 to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/2021 printStairPaths
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 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 | |
| } |
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 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, ""); |
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 printStairPaths(int n, string psf){ | |
| // write your code here | |
| } | |
| int main(){ | |
| int n; | |
| cin >> n; | |
| printStairPaths(n, ""); // function call | |
| } |
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 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