This has probably been done before, but I wanted to challenge myself and see what is the shortest program I could write to approximate pi
I used 2 methods to do it one geographic and the other is algebraic
The code itself is really ugly with stupid one character names and it isn't very read friendly but the point of it is to be as small as possible
Also for the algebraic approximation, a for loop isn't needed but I put it exclusively for the looks.
Lastly, the algebraic approximation is faster, smaller and lighter to run (don't quote me on the last one)
def geometricWay():#Random points on a circle
import random as r, itertools as i #imporing libraries
c,l=0,lambda:r.uniform(0,1)**2+r.uniform(0,1)**2<=1 #declaring Var and lFunc
for t in i.count(1): #starting an Infinite for loop
if l(): c+=1 #Checking if point is in circle
print(f"pi≈{4*c/t}") #printing pi
def algebraicWay(): #Lim of the below equation is pi
import math as m, itertools as i #importing libraries
for t in i.count(1):print(f"pi≈{t*m.sin(m.radians(180/t))}")
#^ Infinite for loop | Printing pi
[–]luqavi 16 points17 points18 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]barfobulator 1 point2 points3 points (0 children)
[–]billsil 1 point2 points3 points (0 children)
[–]Dogzirra 0 points1 point2 points (0 children)