Last active
December 28, 2015 20:29
-
-
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.
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 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