Jump to content

Monte Carlo methods: Difference between revisions

Line 249:
int inside;
foreach (i; 0 .. nthrows)
if (hypot(uniform(0,1.0) ^^ 2 +, uniform(0,1.0) ^^ 2) <= 1)
inside++;
return 4.0 * inside / nthrows;
Line 256:
void main() {
foreach (p; 1 .. 9)
writefln("%11s9s: %07f", 10 ^^ p, pi(10 ^^ p));
}</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.