Skip to content

Instantly share code, notes, and snippets.

@mandyRae
Created March 15, 2016 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandyRae/1b9bac427815a065d920 to your computer and use it in GitHub Desktop.
Save mandyRae/1b9bac427815a065d920 to your computer and use it in GitHub Desktop.
Happy Pi Day!!!!
import time
j = 0
pi = 0
plusminus = True
start_time = time.time()
while True:
if j%2 == 1:
if plusminus == True:
pi += (1/j)
else:
pi -= (1/j)
plusminus = not plusminus
j += 1
if j%1000000 == 0:
print('Time Elapsed:', time.time()-start_time)
if j%100000 ==0:
print('# of terms:',j)
print(pi*4)
#took approx 37,500,000 terms to reach pi to 8 sigfigs or 3.1415926
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment