Skip to content

Instantly share code, notes, and snippets.

@samartioli
Last active December 15, 2015 19:49
Show Gist options
  • Save samartioli/5314204 to your computer and use it in GitHub Desktop.
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"
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))
@samartioli
Copy link
Author

since in python .apend does not return the mutated list, I wrote a helper function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment