+ 10

Challenge # coding problem #

There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time. Given N, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters. For example, if N is 4, then there are 5 unique ways: 1, 1, 1, 12, 1, 11, 2, 11, 1, 22, 2 What if, instead of being able to climb 1 or 2 steps at a time, you could climb any number from a set of positive integers X? For example, if X = {1, 3, 5}, you could climb 1, 3, or 5 steps at a time.

15th Jan 2018, 2:22 PM
CSK
7 Answers
+ 7
Nice challenge ! I made a code that first gives all combinations (printing them) answering your question with X = {a, b, ..., c}, indefinite number of different jumps, and then calculates the total permutations for each combination (not printing them, too many). Finally it gives the total answer. https://code.sololearn.com/cCbHULpV1tLj/#py
16th Jan 2018, 1:05 AM
CĂ©pagrave
CĂ©pagrave - avatar
+ 22
https://www.sololearn.com/Discuss/853148/?ref=app
15th Jan 2018, 3:12 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 7
hi
16th Jan 2018, 7:12 PM
Alireza Sohrabi
Alireza Sohrabi - avatar
+ 4
I made a variation of it, to be able to print only the result (total number of ways to climb) for a range of integers (1 to 30 for ex) with X = {a, b, c, ...} https://code.sololearn.com/cxkF8zDbqhTH/#py
16th Jan 2018, 1:20 AM
CĂ©pagrave
CĂ©pagrave - avatar
+ 4
all variations for 1 or 2 steps at a time. https://code.sololearn.com/c8AwXCVrmL00/?ref=app
17th Jan 2018, 5:10 PM
davy hermans
davy hermans - avatar
17th Jan 2018, 6:29 PM
davy hermans
davy hermans - avatar
+ 2
Not your question but gives the answer for any set solution https://code.sololearn.com/cWPi0YALbaFP/?ref=app
15th Jan 2018, 8:38 PM
VcC
VcC - avatar