Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue