Created
April 18, 2020 09:30
-
-
Save abap34/e93bd67e122040cead4afb3d5b565c2f 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
<!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