Skip to content

Commit

Permalink
Update pi.py
Browse files Browse the repository at this point in the history
Took the "factor" term outside the braket of infinite summation so that they all have to be added only once
  • Loading branch information
abhitrueprogrammer authored Apr 10, 2022
1 parent 9eba623 commit a0298d3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions code/pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ def estimate_pi():
while True:
num = factorial(4*k) * (1103 + 26390*k)
den = factorial(k)**4 * 396**(4*k)
term = factor * num / den
total += term

total += num / den
term = factor * num/den

if abs(term) < 1e-15:
break
k += 1

return 1 / total
return 1 / (factor * total)

print(estimate_pi())

0 comments on commit a0298d3

Please sign in to comment.