Created
January 27, 2011 00:37
-
-
Save jsundram/797835 to your computer and use it in GitHub Desktop.
problem 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
int step(int curr, int steps, const int n) | |
{ | |
curr += steps; | |
if (curr < n) | |
return step(curr, 1, n) + step(curr, 2, n); | |
if (curr == n) | |
return 1; | |
return 0; | |
} | |
int main() | |
{ | |
const int n; // whatever. | |
if (n < 1) { | |
std::cout << "Not possible to climb this ladder" << std::endl; | |
return 1; // bad n | |
} | |
int steps = step(0, 1, n) + step(0, 2, n); | |
std::cout << "Total ways of climbing ladder: " << steps << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment