Created
August 5, 2017 18:42
-
-
Save caervs/8e734cdd7302e453ffd9720610335c2b to your computer and use it in GitHub Desktop.
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
import math | |
def side_length(n): | |
""" | |
return the side length of a polygon inscribed in a unit circle | |
The number of sides that the polygon has is (2 ** n) * 6 | |
""" | |
if n == 0: | |
return 1.0 | |
l0 = (side_length(n - 1) / 2) | |
l1 = 1 - math.sqrt(1 - l0**2) | |
return math.sqrt(l0**2 + l1**2) | |
def pi(n): | |
return (2**n * 3) * side_length(n) | |
def main(): | |
print pi(500) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment