Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Last active December 28, 2015 20:29
Show Gist options
  • Save animatedlew/7557341 to your computer and use it in GitHub Desktop.
Save animatedlew/7557341 to your computer and use it in GitHub Desktop.
This function takes a set of coordinates on a grid and returns the number of discrete paths that can be taken from the origin.
def count_paths(x, y):
if x is 0 and y is 0:
return 1
else:
a = 0 if y is 0 else count_paths(x, y-1)
b = 0 if x is 0 else count_paths(x-1, y)
return a + b
destination = (5, 3)
# 56
print(count_paths(*destination))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment