-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpidigits.py
41 lines (30 loc) · 859 Bytes
/
pidigits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''
Calculation of the pi digits.
'''
def Enumerator( N0 ):
N = N0
while True:
yield N
N += 1
def A( N, k, a ):
return pow( 16, N-k, 8 * k + a ) / float( 8. * k + a )
def B( N, k, a ):
return pow( 16, N-k ) / float( 8. * k + a )
def Asum( N, a ):
return sum( A( N, k, a ) for k in xrange(N-1,-1,-1) )
def Bsum( N, a, p = 16 ):
p += 10
return sum( B( N, k, a ) for k in xrange(N+p,N-1,-1) )
# Sum = 0.
# for k in Enumerator(N):
# new = B( N, k, p )
# Sum += new
# if not new:
# return Sum
def ABsum( N, a, p = 16 ):
return Asum( N, a ) + Bsum( N, a, p )
def Nthpi( N ):
return str( int( str( int( 4 * ABsum( N, 1 ) - 2 * ABsum( N, 4 ) - ABsum( N, 5 ) - ABsum( N, 6 ) ) ), 16 ) )
def pi( N = 100 ):
return ''.join( map( Nthpi, range(N) ) )
print pi()