Skip to content

Instantly share code, notes, and snippets.

@caervs
Created August 5, 2017 18:42
Show Gist options
  • Save caervs/8e734cdd7302e453ffd9720610335c2b to your computer and use it in GitHub Desktop.
Save caervs/8e734cdd7302e453ffd9720610335c2b to your computer and use it in GitHub Desktop.
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