Problem 015

git-svn-id: file:///srv/svn/euler@40 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
Correl Roush 2010-04-12 15:53:19 +00:00
parent e4deb217d1
commit d3dba4b9cd

33
e015.py Normal file
View file

@ -0,0 +1,33 @@
"""
Calculate the number of possible paths from the top left corner to the bottom
right, without backtracking (no moving up or left)
i.e., for a 2x2 grid:
_ _
|_|_|
|_|_|
Paths to each point, forming a Pascal Triangle:
1 1 1
1 2 3
1 3 6
001 001 001 001
001 002 003 004
001 003 006 010
001 004 010 020
"""
def pascal(row, col):
val = 1
r = row + 1
for c in range(1, col + 1):
val = (val * ((r - c) / float(c)))
return int(val)
def paths(size):
return pascal(size + (size - 2), size - 1)
if __name__ == '__main__':
# 20x20 grid
# Points = cubes + 1
size = 21
print 'Paths: ', paths(size)