Euler Project question 15 in python way

# This Python file uses the following encoding: utf-8
# Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.


# How many such routes are there through a 20×20 grid?
# pictures see at https://projecteuler.net/problem=15
import time
start = time.time()
def factorial(n):
    sum = 1
    for i in range(2, n+1):
        sum *= i
    return sum
print "%s ways ways found in %s seconds" % (factorial(40)/(factorial(20)*factorial(20)), time.time() - start)

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。