Skip to content

Instantly share code, notes, and snippets.

@jsundram
Created January 27, 2011 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsundram/797835 to your computer and use it in GitHub Desktop.
Save jsundram/797835 to your computer and use it in GitHub Desktop.
problem 1
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