Advertisement
flypip

Flypi (PI Algorithme)

Nov 1st, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. #! /usr/bin/env python
  3.  
  4. import sys
  5.  
  6.  
  7.  
  8. def main():
  9.     k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
  10.     while 1:
  11.         p, q, k = k*k, 2L*k+1L, k+1L
  12.         a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
  13.         d, d1 = a/b, a1/b1
  14.         while d == d1:
  15.             output(d)
  16.             a, a1 = 10L*(a%b), 10L*(a1%b1)
  17.             d, d1 = a/b, a1/b1
  18.  
  19. def output(d):
  20.     sys.stdout.write(`int(d)`)
  21.     sys.stdout.flush()
  22.     #ecriture en continue du chiffre
  23.     pi = open("flypi.html", "a")
  24.     pi.write(`int(d)`)
  25.     pi.write("\n")
  26.     pi.close()
  27.    
  28.  
  29. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement