+ 147

[ASSIGNMENT] ๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰ A Man On Stairs of n Steps . ๐Ÿ‘คโœ๐Ÿ”†

A man can jump 1 or 2 steps at a time , find number of ways in which the man can climb n number of steps ? /* example ::: input :: 3 output :: 3 // because 3 ways 1st way) 3 times 1 step (1,1,1) 2nd way)1 time 2 steps together & then 1 step more(2,1) 3rd way) 1 step & then 1 time 2 steps together(1,2) Remember man can take 1 or 2 steps at a time */ //level :: easy & interesting //simple approach is welcome , with some explanation HAPPY CODING โ˜บ๐Ÿ‘

12th Nov 2017, 6:28 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
113 Answers
+ 43
After some observations, if steps = 1: ways = 1 if steps = 2: ways = 2 if steps = 3: ways = 3 if steps = 4: ways = 5..... And finally, I ended up with Fibonacci sequence 1, 2, 3, 5, 8, 13, 21..... https://code.sololearn.com/cX917vOg9Mrl/?ref=app
13th Nov 2017, 3:21 PM
#RahulVerma
#RahulVerma - avatar
+ 38
thnx ๐Ÿ˜Š๐Ÿ˜Š @river,bool1
13th Nov 2017, 4:11 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 33
Thank you for the challenge ๐Ÿ‘ Here's my try : https://code.sololearn.com/clieRlKMyz21/?ref=app
12th Nov 2017, 9:12 PM
LukArToDo
LukArToDo - avatar
+ 30
@tai welcome to Sl https://www.sololearn.com/Discuss/595802/?ref=app u can start with language u want to learn //happy codingโ˜บ
14th Nov 2017, 11:46 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 29
i will give a simple approach to this challenge later โ˜บ //just give it a try ๐Ÿ‘
12th Nov 2017, 6:57 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 29
thnx ๐Ÿ˜Š๐Ÿ˜Š swapnil,kartikey
13th Nov 2017, 4:03 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 27
My try - https://code.sololearn.com/W4h1B7NEBnk0/?ref=app By the way, @Gaurav congrats for cotd.
13th Nov 2017, 4:00 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
13th Nov 2017, 2:08 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 15
I tried to approach this problem by finding a mathematical pattern for the terms. 1 stair: 1 = 1 way 2 stairs: 11 2 = 2 ways 3 stairs: 111 12 21 = 3 ways 4 stairs: 1111 112 121 211 22 = 5 ways 5 stairs: 11111 1112 1121 1211 2111 122 212 221 = 8 ways 6 stairs: 111111 11112 11121 11211 12111 21111 1122 1212 1221 2112 2121 2211 222 = 13 ways 7 stairs: 1111111 111112 111121 111211 112111 121111 211111 11122 11212 11221 12112 12121 12211 21112 21121 21211 22111 1222 2122 2212 2221 = 21 ways ... {1, 2, 3, 5, 8, 13, 21, ...} is the Fibonacci sequence starting from the third term (F2). The Fibonacci sequence: F0 = 0 F1 = 1 F2 = 1 F3 = 2 F4 = 3 F5 = 5 ... This means that to solve the initial problem one can use this equation: <number of ways to climb the stairs> = F(<number of stairs>-1) To simplify the task I rephrased the problem to "Given n, find the Fibonacci number of term F(n-1)" Here are my codes (JavaScript and C++): https://code.sololearn.com/Wc7Hle99U3JS/?ref=app https://code.sololearn.com/cqYg2kTfY0wx/?ref=app
13th Nov 2017, 5:35 PM
Augustinas Lukauskas
Augustinas Lukauskas - avatar
+ 14
gaurav we can use a whole set of permutations & combinations here, i think ๐Ÿ˜ฐ๐Ÿ˜ฐ
12th Nov 2017, 6:59 PM
Ankush Kumar
Ankush Kumar - avatar
12th Nov 2017, 8:59 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 12
Gaurav,great challenge,im lost!๐Ÿค”๐Ÿค”
12th Nov 2017, 6:38 PM
แ Œแ ŒCode X
แ Œแ ŒCode X - avatar
+ 12
Congrats for COTD
13th Nov 2017, 4:01 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 11
COT DAY CONGRATS
13th Nov 2017, 4:14 PM
Ankush Kumar
Ankush Kumar - avatar
+ 10
not in that kind of state but i will try after a month
12th Nov 2017, 6:52 PM
Ankush Kumar
Ankush Kumar - avatar
+ 10
@Charan here is my Solotion https://code.sololearn.com/cvNgxxjbX7sg
13th Nov 2017, 7:16 PM
Said BAHAOUARY
Said BAHAOUARY - avatar
+ 10
My try.. Doesn't work for more than 19 steps, any help very appreciated! https://code.sololearn.com/cM1XQdLu5zm6/?ref=app
17th Nov 2017, 1:14 PM
AZTECCO
AZTECCO - avatar
+ 9
Since there's no answer in python yet, I'll post this clumsy one I made before any research (it works only up to 4, though hahaha) https://code.sololearn.com/cno0PYFgy4tO/?ref=app
13th Nov 2017, 1:59 AM
Murillo Pyaia Alves Paixรฃo
Murillo Pyaia Alves Paixรฃo - avatar
+ 9
Congrats @ COTD Gaurav๐Ÿป๐Ÿบ๐Ÿ’“and cheeeeeers
13th Nov 2017, 4:08 PM
Daljeet Singh
Daljeet Singh - avatar