Created
March 1, 2020 14:41
-
-
Save lysenko-sergey-developer/1891b2c9954e545b47d61a4572675822 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function estimatePi(n) { | |
let numPointCircle = 0; | |
let numPointTotal = 0; | |
for (let i = 0; i < n; i++) { | |
const x = Math.round(Math.random()) | |
const y = Math.round(Math.random()) | |
let distance = x ** 2 + y ** 2; | |
if (distance <= 1) { | |
numPointCircle++; | |
} | |
numPointTotal++; | |
} | |
return 4 * numPointCircle / numPointTotal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment