Created
July 28, 2020 15:54
-
-
Save CodeDrome/4f59b29b32316769d7694d5678463c4a to your computer and use it in GitHub Desktop.
estimatingpi.py part 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nilakantha(): | |
""" | |
Named after the 15th century Indian mathematician Nilakantha Somayaji | |
""" | |
print("Nilakantha\n=========") | |
iterations = 1000000 | |
multiplier = 1.0 | |
start_denominator = 2.0 | |
pi = 3.0 | |
for i in range(1, iterations + 1): | |
pi += ( (4.0 / (start_denominator * (start_denominator + 1.0) * (start_denominator + 2.0)) ) * multiplier) | |
start_denominator += 2.0 | |
multiplier *= -1.0 | |
print_as_text(pi) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment