Question: Write a recursive method called waysToClimb that takes a positive integer value representing a number of stairs and prints each unique way to climb a
Write a recursive method called waysToClimb that takes a positive integer value representing a number of stairs and prints each unique way to climb a staircase of that height, taking strides of one or two stairs at a time. Do not use any loops. Output each way to climb the stairs on its own line, using a 1 to indicate a small stride of 1 stair, and a 2 to indicate a large stride of 2 stairs. The order in which you output the possible ways to climb the stairs is not important, so long as you list the right overall set of ways. For example, the call waysToClimb(3); should produce the following output:
[1, 1, 1]
[1, 2]
[2, 1]
The call waysToClimb(4) ; should produce the following output:
[1, 1, 1, 1]
[1, 1, 2]
[1, 2, 1]
[2, 1, 1]
[2, 2]
Step by Step Solution
3.44 Rating (160 Votes )
There are 3 Steps involved in it
Outputs all ways to climb the given number of stairs ... View full answer
Get step-by-step solutions from verified subject matter experts
