Discuss / Python / 借鉴楼上大神

借鉴楼上大神

Topic source

最帅的仔

#1 Created at ... [Delete] [Delete and Lock User]
import itertools

def pi(N):
    
    ns = itertools.takewhile(lambda a: a < 2 * N, itertools.count(1, 2))

    fat = itertools.cycle([1, -1])

    return sum(map(lambda a: 4 * next(fat) / a, ns))

関筅苼

#2 Created at ... [Delete] [Delete and Lock User]

我发现数学跟不上的,这个算法也想不明白。卡壳了


  • 1

Reply