Created
November 8, 2020 20:26
-
-
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 ?
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Si, Si estoy usando la distancia cuadrada