We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 13a1011 commit 34369b0Copy full SHA for 34369b0
1 file changed
tests/snapshots/examples/calculate-pi-monte.ts
@@ -1,14 +1,14 @@
1
2
{
3
// Monte Carlo simulation
4
- function calculatePI(cycles: number): number {
+ function calculatePI(cycles: number, r: number): number {
5
let inside = 0;
6
7
for (let i = 0; i < cycles; i++) {
8
- let x = Math.random() * 2 - 1;
9
- let y = Math.random() * 2 - 1;
+ let x = Math.random() * r;
+ let y = Math.random() * r;
10
11
- if ((x*x + y*y) < 1) {
+ if ((x*x + y*y) < r*r) {
12
inside++
13
}
14
@@ -17,5 +17,5 @@
17
18
19
console_log("Monte Carlo simulation");
20
- console_log(calculatePI(10000000));
+ console_log(calculatePI(1e8, 2 ** 16));
21
0 commit comments