Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Pi/D/pi-1.d
Normal file
38
Task/Pi/D/pi-1.d
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import std.stdio, std.conv, std.string;
|
||||
|
||||
struct PiDigits {
|
||||
immutable uint nDigits;
|
||||
|
||||
int opApply(int delegate(ref string /*chunk of pi digit*/) dg){
|
||||
// Maximum width for correct output, for type ulong.
|
||||
enum size_t width = 9;
|
||||
|
||||
enum ulong scale = 10UL ^^ width;
|
||||
enum ulong initDigit = 2UL * 10UL ^^ (width - 1);
|
||||
enum string formatString = "%0" ~ text(width) ~ "d";
|
||||
|
||||
immutable size_t len = 10 * nDigits / 3;
|
||||
auto arr = new ulong[len];
|
||||
arr[] = initDigit;
|
||||
ulong carry;
|
||||
|
||||
foreach (i; 0 .. nDigits / width) {
|
||||
ulong sum;
|
||||
foreach_reverse (j; 0 .. len) {
|
||||
auto quo = sum * (j + 1) + scale * arr[j];
|
||||
arr[j] = quo % (j*2 + 1);
|
||||
sum = quo / (j*2 + 1);
|
||||
}
|
||||
auto yield = format(formatString, carry + sum/scale);
|
||||
if (dg(yield))
|
||||
break;
|
||||
carry = sum % scale;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
foreach (d; PiDigits(100))
|
||||
writeln(d);
|
||||
}
|
||||
33
Task/Pi/D/pi-2.d
Normal file
33
Task/Pi/D/pi-2.d
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import std.stdio, std.bigint;
|
||||
|
||||
void main() {
|
||||
int ndigits = 0;
|
||||
auto q = BigInt(1);
|
||||
auto r = BigInt(0);
|
||||
auto t = q;
|
||||
auto k = q;
|
||||
auto n = BigInt(3);
|
||||
auto l = n;
|
||||
|
||||
bool first = true;
|
||||
while (ndigits < 1_000) {
|
||||
if (4 * q + r - t < n * t) {
|
||||
write(n); ndigits++;
|
||||
if (ndigits % 70 == 0) writeln();
|
||||
if (first) { first = false; write('.'); }
|
||||
auto nr = 10 * (r - n * t);
|
||||
n = ((10 * (3 * q + r)) / t) - 10 * n;
|
||||
q *= 10;
|
||||
r = nr;
|
||||
} else {
|
||||
auto nr = (2 * q + r) * l;
|
||||
auto nn = (q * (7 * k + 2) + r * l) / (t * l);
|
||||
q *= k;
|
||||
t *= l;
|
||||
l += 2;
|
||||
k++;
|
||||
n = nn;
|
||||
r = nr;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue