Skip to content

Instantly share code, notes, and snippets.

@Murgio
Created December 29, 2018 20:44
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 Murgio/ce972c49688041ca840015ea86eef67e to your computer and use it in GitHub Desktop.
Save Murgio/ce972c49688041ca840015ea86eef67e to your computer and use it in GitHub Desktop.
from random import random
def estimate_pi(n=1e7) -> "area":
def helper(in_circle, n):
if n == 0: return in_circle
if random()**2 + random()**2 <= 1:
return helper(in_circle+1, n-1)
return helper(in_circle, n-1)
in_circle = helper(0, n)
return 4 * in_circle / n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment