Skip to content

Instantly share code, notes, and snippets.

@abap34
Created April 18, 2020 09:30
Show Gist options
  • Save abap34/e93bd67e122040cead4afb3d5b565c2f to your computer and use it in GitHub Desktop.
Save abap34/e93bd67e122040cead4afb3d5b565c2f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<script>
var N;
var count = 0;
function inCircle(x,y){
return (x * x + y * y) <= 1;
}
N = Number(prompt("Iteration:"));
document.write("Iteration:",N,"<br>")
document.write("start simulate...")
for (var i = 0; i <= N; i++){
x = Math.random()
y = Math.random()
if (inCircle(x,y)) count++;
if (i % 100 == 0) {
pi = (4 * count) / i;
document.write(i,":",pi,"<br>");
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment