2015-02-20 00:35:01 -05:00
|
|
|
void main() {
|
|
|
|
|
import std.stdio, std.random, std.math, std.algorithm, std.range;
|
2013-04-10 21:29:02 -07:00
|
|
|
|
2015-02-20 00:35:01 -05:00
|
|
|
immutable isIn = (int) => hypot(uniform01, uniform01) <= 1;
|
|
|
|
|
immutable pi = (in int n) => 4.0 * n.iota.count!isIn / n;
|
2013-04-10 21:29:02 -07:00
|
|
|
|
2013-10-27 22:24:23 +00:00
|
|
|
foreach (immutable p; 1 .. 8)
|
2013-04-10 21:29:02 -07:00
|
|
|
writefln("%10s: %07f", 10 ^^ p, pi(10 ^^ p));
|
|
|
|
|
}
|