Last active
December 15, 2015 19:49
-
-
Save samartioli/5314204 to your computer and use it in GitHub Desktop.
Python solution to problem: "A person can walk/hop 1, 2 or 3 steps at a time, find all the possible ways to walk/hop down n steps"
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
def append_return(n,L): | |
M=L[:] | |
M.append(n) | |
return M | |
def steps(n, L=[]): | |
if n == 0: | |
print L | |
if n >= 1: | |
steps(n-1, append_return(1,L)) | |
if n >= 2: | |
steps(n-2, append_return(2,L)) | |
if n >= 3: | |
steps(n-3, append_return(3,L)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
since in python .apend does not return the mutated list, I wrote a helper function