Skip to content

Commit ac14455

Browse files
Combinatoric solution using Pascal's Triangle to Problem 15
1 parent 301c907 commit ac14455

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Project Euler/Problem 15/sol1.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from __future__ import print_function
2+
from math import factorial, ceil
3+
4+
def lattice_paths(n):
5+
n = 2*n #middle entry of odd rows starting at row 3 is the solution for n = 1, 2, 3,...
6+
k = n/2
7+
8+
return factorial(n)/(factorial(k)*factorial(n-k))
9+
10+
if __name__ == '__main__':
11+
import sys
12+
13+
if len(sys.argv) == 1:
14+
print(lattice_paths(20))
15+
else:
16+
try:
17+
n = int(sys.argv[1])
18+
print(lattice_paths(n))
19+
except ValueError:
20+
print('Invalid entry - please enter a number.')

0 commit comments

Comments
 (0)