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()))