Moved more problems to Python.

This commit is contained in:
2019-07-14 23:58:22 -04:00
parent 86e68eeee2
commit 0ab214633e
14 changed files with 476 additions and 0 deletions

21
python/e015.py Normal file
View File

@@ -0,0 +1,21 @@
from math import factorial
def get_number_of_routes(n):
"""
There are n down and n right moves which means 2 * n moves
in total. All permutations are calculated with (2n)!. Next redundant
moves have to be canceled out. The combinations for only down moves
or only right moves would (if they were different symbols) be n!.
Hence, the denominator is (n!)^2.
"""
return factorial(2 * n) // (factorial(n) * factorial(n))
def euler_015():
return get_number_of_routes(20)
assert(get_number_of_routes(2) == 6)
assert(euler_015() == 137846528820)
print("e015.py: {}".format(euler_015()))