Skip to content

Instantly share code, notes, and snippets.

@SimonRichardson
Last active October 1, 2018 13:28
Show Gist options
  • Save SimonRichardson/ad3559d14d1dbfa09ac50ea3a36c920f to your computer and use it in GitHub Desktop.
Save SimonRichardson/ad3559d14d1dbfa09ac50ea3a36c920f to your computer and use it in GitHub Desktop.
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