““

from math import pi

from time import time

x=1

difference=pi-3

D=pi-3

Time=time()

while D!=0:

y=round(pi*x)

D=abs(pi-float(y)/x)

if D<difference or x==1:

difference=D

print str(y)+'/'+str(x)+'='+str(float(y)/x)+'. It is '+str(D)+' away from pi! Time spent: '+str(time()-Time)+' seconds, precisely.'

if D==0: break

Time=time()

x+=1

“`

It times the amount of time to take each approximation and only gives the best ones.

]]>These give approximations like 3,22/7,333/106,355/113,103993/33102,104348/33215,208341/66317…….

22/7′s difference from pi is less than the reciprocal of its denominator times the next fraction’s denominator (i.e. 7*106=742), or 1 / 742. For 355 / 113, 1 / (113 * 33102) = 1 / 3740526!

]]>11470607307161132716588859789437271840000798468219508525085448960062402821241970285202775001996784319885772780138414238670402064758

/

3651207706401417758577438077383177726074790491037819709434096621864877255825019944180015629313589782838738505101104441533461516175

2595730897165797211593340467841630035030853330521178267351313167 / 826246806440593758242827735111030202858868304763792133731752324

Don’t ask me how accurate it is! I only know there is no smaller fraction with more accuracy.

]]>Thanks for this great article. When the time comes, I promise now I will not write my own tutorial like it seems to be proper, but just link here. Hard to resist the temptation. ]]>

I also have a stupid question: I can’t get this code to compile (it complains about a lack of `main` function)…

]]>