Skip to content

Instantly share code, notes, and snippets.

@alirioangel
Created November 8, 2020 20:26
Show Gist options
  • Save alirioangel/b55640838a75bb892e9d3a0c11116089 to your computer and use it in GitHub Desktop.
Save alirioangel/b55640838a75bb892e9d3a0c11116089 to your computer and use it in GitHub Desktop.
Si tienes un arreglo de pares de numeros aleatorios que van de 0 a 1 cual es el valor aproximado de PI ?
import random
def estimate_pi(number_of_needle):
needles_on_circle = 0
for _ in range(number_of_needle):
x = random.uniform(0,1)
y = random.uniform(0,1)
distance = x**2 + y**2
if distance <= 1:
needles_on_circle += 1
return 4 * needles_on_circle / number_of_needle ## buffon's Needle trick
@alirioangel
Copy link
Author

Si, Si estoy usando la distancia cuadrada

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment