Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
8
Task/Generator-Exponential/D/generator-exponential-1.d
Normal file
8
Task/Generator-Exponential/D/generator-exponential-1.d
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
void main() {
|
||||
import std.stdio, std.bigint, std.range, std.algorithm;
|
||||
|
||||
auto squares = 0.sequence!"n".map!(i => i.BigInt ^^ 2);
|
||||
auto cubes = 0.sequence!"n".map!(i => i.BigInt ^^ 3);
|
||||
|
||||
squares.setDifference(cubes).drop(20).take(10).writeln;
|
||||
}
|
||||
12
Task/Generator-Exponential/D/generator-exponential-2.d
Normal file
12
Task/Generator-Exponential/D/generator-exponential-2.d
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
void main() {
|
||||
import std.stdio, std.bigint, std.range, std.algorithm;
|
||||
|
||||
auto squares = 0.sequence!"n".map!(i => i.BigInt ^^ 2);
|
||||
auto cubes = 0.sequence!"n".map!(i => i.BigInt ^^ 3);
|
||||
|
||||
squares
|
||||
.filter!(s => cubes.find!(c => c >= s).front != s)
|
||||
.drop(20)
|
||||
.take(10)
|
||||
.writeln;
|
||||
}
|
||||
47
Task/Generator-Exponential/D/generator-exponential-3.d
Normal file
47
Task/Generator-Exponential/D/generator-exponential-3.d
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import std.stdio, std.bigint, std.range, std.algorithm;
|
||||
|
||||
struct Filtered(R1, R2) if (is(ElementType!R1 == ElementType!R2)) {
|
||||
R1 s1;
|
||||
R2 s2;
|
||||
alias ElementType!R1 T;
|
||||
T front, source, filter;
|
||||
|
||||
this(R1 r1, R2 r2) {
|
||||
s1 = r1;
|
||||
s2 = r2;
|
||||
source = s1.front;
|
||||
filter = s2.front;
|
||||
popFront;
|
||||
}
|
||||
|
||||
static immutable empty = false;
|
||||
|
||||
void popFront() {
|
||||
while (true) {
|
||||
if (source > filter) {
|
||||
s2.popFront;
|
||||
filter = s2.front;
|
||||
continue;
|
||||
} else if (source < filter) {
|
||||
front = source;
|
||||
s1.popFront;
|
||||
source = s1.front;
|
||||
break;
|
||||
}
|
||||
s1.popFront;
|
||||
source = s1.front;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto filtered(R1, R2)(R1 r1, R2 r2) // Helper function.
|
||||
if (isInputRange!R1 && isInputRange!R2 &&
|
||||
is(ElementType!R1 == ElementType!R2)) {
|
||||
return Filtered!(R1, R2)(r1, r2);
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto squares = 0.sequence!"n".map!(i => i.BigInt ^^ 2);
|
||||
auto cubes = 0.sequence!"n".map!(i => i.BigInt ^^ 3);
|
||||
filtered(squares, cubes).drop(20).take(10).writeln;
|
||||
}
|
||||
34
Task/Generator-Exponential/D/generator-exponential-4.d
Normal file
34
Task/Generator-Exponential/D/generator-exponential-4.d
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import std.stdio;
|
||||
|
||||
auto powers(in double e) pure nothrow {
|
||||
double i = 0;
|
||||
return () => i++ ^^ e;
|
||||
}
|
||||
|
||||
auto filter2(D)(D af, D bf) {
|
||||
double a = af(), b = bf();
|
||||
|
||||
return {
|
||||
double r;
|
||||
while (true) {
|
||||
if (a < b) {
|
||||
r = a;
|
||||
a = af();
|
||||
break;
|
||||
}
|
||||
if (b == a)
|
||||
a = af();
|
||||
b = bf();
|
||||
}
|
||||
return r;
|
||||
};
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto fgen = filter2(2.powers, 3.powers);
|
||||
foreach (immutable i; 0 .. 20)
|
||||
fgen();
|
||||
foreach (immutable i; 0 .. 10)
|
||||
write(fgen(), " ");
|
||||
writeln;
|
||||
}
|
||||
28
Task/Generator-Exponential/D/generator-exponential-5.d
Normal file
28
Task/Generator-Exponential/D/generator-exponential-5.d
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import std.stdio, std.range, std.algorithm, std.concurrency, std.bigint;
|
||||
|
||||
auto powers(in uint m) pure nothrow @safe {
|
||||
return 0.sequence!"n".map!(i => i.BigInt ^^ m);
|
||||
}
|
||||
|
||||
auto filtered(R1, R2)(R1 r1, R2 r2) /*@safe*/
|
||||
if (isForwardRange!R1 && isForwardRange!R2 &&
|
||||
is(ElementType!R1 == ElementType!R2)) {
|
||||
return new Generator!(ElementType!R1)({
|
||||
auto v = r1.front; r1.popFront;
|
||||
auto f = r2.front; r2.popFront;
|
||||
|
||||
while (true) {
|
||||
if (v > f) {
|
||||
f = r2.front; r2.popFront;
|
||||
continue;
|
||||
} else if (v < f)
|
||||
yield(v);
|
||||
v = r1.front; r1.popFront;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto squares = 2.powers, cubes = 3.powers;
|
||||
filtered(squares, cubes).drop(20).take(10).writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue