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)
| 10 | |
| 11 | |
| 12 | def 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 | |
| 35 | if __name__ == "__main__": |