Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created April 30, 2016 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f369668487026e46b4a294442ec85759 to your computer and use it in GitHub Desktop.
Save anonymous/f369668487026e46b4a294442ec85759 to your computer and use it in GitHub Desktop.
def compute_pi(n):
denom = 1
toggle = 1
result = 0
for x in range(n, 0, -1):
result += toggle * (1 / denom)
denom += 2
toggle *= -1
result *= 4
return result
print("Pi: ", compute_pi(int(input("Enter n for pi:"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment