Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,14 +1,14 @@
import std.stdio, std.random, std.math;
double pi(in int nthrows) {
int inside;
foreach (i; 0 .. nthrows)
if (hypot(uniform(0, 1.0), uniform(0, 1.0)) <= 1)
double pi(in uint nthrows) /*nothrow*/ @safe /*@nogc*/ {
uint inside;
foreach (immutable i; 0 .. nthrows)
if (hypot(uniform01, uniform01) <= 1)
inside++;
return 4.0 * inside / nthrows;
}
void main() {
foreach (p; 1 .. 8)
foreach (immutable p; 1 .. 8)
writefln("%10s: %07f", 10 ^^ p, pi(10 ^^ p));
}

View file

@ -1,9 +1,9 @@
import std.stdio, std.random, std.math, std.algorithm, std.range;
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() {
import std.stdio, std.random, std.math, std.algorithm, std.range;
immutable isIn = (int) => hypot(uniform01, uniform01) <= 1;
immutable pi = (in int n) => 4.0 * n.iota.count!isIn / n;
foreach (immutable p; 1 .. 8)
writefln("%10s: %07f", 10 ^^ p, pi(10 ^^ p));
}