Last active
October 1, 2018 13:28
-
-
Save SimonRichardson/ad3559d14d1dbfa09ac50ea3a36c920f to your computer and use it in GitHub Desktop.
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
const n = 100000; | |
let hit = 0; | |
for (let i = 0; i < n; i++) { | |
const x = Math.random(); | |
const y = Math.random(); | |
if (x *x + y * y < 1) { | |
hit += 1; | |
} | |
} | |
console.log(4.0 * hit / n); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment