This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,10 +1,9 @@
import std.stdio, std.random, std.math, std.algorithm, std.range;
bool isIn(int){ return hypot(uniform(0,1.0), uniform(0,1.0)) <= 1; }
double pi(in int n) { return 4.0 * count!isIn(iota(n)) / n; }
enum isIn = (int) => hypot(uniform(0, 1.0), uniform(0, 1.0)) <= 1;
enum pi = (in int n) => 4.0 * n.iota.count!isIn / n;
void main() {
foreach (p; 1 .. 8)
foreach (immutable p; 1 .. 8)
writefln("%10s: %07f", 10 ^^ p, pi(10 ^^ p));
}