File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
contents/monte_carlo_integration/code/nim Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -3,23 +3,23 @@ import math
33
44randomize ()
55
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
88
99proc 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
1212
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)
1717
18- if in_circle (x,y, radius):
19- count += 1
18+ if in_circle (x, y, radius):
19+ count += 1
2020
21- var pi_estimate: float = 4 * count / samples
22- return pi_estimate
21+ let pi_estimate: float = 4 * count / samples
22+ return pi_estimate
2323
2424let estimate: float = monte_carlo (1000000 )
2525
You can’t perform that action at this time.
0 commit comments