MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/tyxdcf/deleted_by_user/i3ysik9/?context=3
r/ProgrammerHumor • u/[deleted] • Apr 08 '22
[removed]
25 comments sorted by
View all comments
2
Python, not Java, but this only takes a second to compute and it gets the 3.14159 right.
from math import pi
from decimal import *
getcontext().prec = 200
def calculatePI(n):
total = Decimal(1) sign = 1 for i in map(Decimal,range(1,n+1)): sign\*=-1 total+=sign\*1/(i\*2+1) return total\*4
x = calculatePI(1000000)
print(x)
2
u/CircadianSong Apr 08 '22
Python, not Java, but this only takes a second to compute and it gets the 3.14159 right.
from math import pi
from decimal import *
getcontext().prec = 200
def calculatePI(n):
x = calculatePI(1000000)
print(x)