File tree 1 file changed +12
-12
lines changed
contents/monte_carlo_integration/code/nim
1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -3,23 +3,23 @@ import math
3
3
4
4
randomize ()
5
5
6
- proc in_circle (x,y, radius: float ): bool =
7
- return x * x + y * y < radius * radius
6
+ proc in_circle (x, y, radius: float ): bool =
7
+ return x * x + y * y < radius * radius
8
8
9
9
proc monte_carlo (samples: int ): float =
10
- const radius: float = 1
11
- var count: int = 0
10
+ const radius: float = 1
11
+ var count: int = 0
12
12
13
- for i in 0 .. < samples:
14
- var
15
- x: float = random (radius)
16
- y: float = random (radius)
13
+ for i in 0 .. < samples:
14
+ let
15
+ x: float = random (radius)
16
+ y: float = random (radius)
17
17
18
- if in_circle (x,y, radius):
19
- count += 1
18
+ if in_circle (x, y, radius):
19
+ count += 1
20
20
21
- var pi_estimate: float = 4 * count / samples
22
- return pi_estimate
21
+ let pi_estimate: float = 4 * count / samples
22
+ return pi_estimate
23
23
24
24
let estimate: float = monte_carlo (1000000 )
25
25
You can’t perform that action at this time.
0 commit comments