MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_015/sol1.py:12–32  ·  view source on GitHub ↗

Returns the number of paths possible in a n x n grid starting at top left corner going to bottom right corner and being able to move right and down only. >>> solution(25) 126410606437752 >>> solution(23) 8233430727600 >>> solution(20) 137846528820 >>> solutio

(n: int = 20)

Source from the content-addressed store, hash-verified

10
11
12def solution(n: int = 20) -> int:
13 """
14 Returns the number of paths possible in a n x n grid starting at top left
15 corner going to bottom right corner and being able to move right and down
16 only.
17 >>> solution(25)
18 126410606437752
19 >>> solution(23)
20 8233430727600
21 >>> solution(20)
22 137846528820
23 >>> solution(15)
24 155117520
25 >>> solution(1)
26 2
27 """
28 n = 2 * n # middle entry of odd rows starting at row 3 is the solution for n = 1,
29 # 2, 3,...
30 k = n // 2
31
32 return int(factorial(n) / (factorial(k) * factorial(n - k)))
33
34
35if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

factorialFunction · 0.90

Tested by

no test coverage detected