This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,20 @@
import std.stdio;
T[] forwardDifference(T)(in T[] data, in int level) pure nothrow
in {
assert(level >= 0 && level < data.length);
} body {
//auto result = data.dup; // not nothrow
auto result = data ~ []; // slower
foreach (i; 0 .. level)
foreach (j, ref el; result[0 .. $ - i - 1])
el = result[j + 1] - el;
result.length -= level;
return result;
}
void main() {
auto data = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5];
foreach (level; 0 .. data.length)
writeln(forwardDifference(data, level));
}

View file

@ -0,0 +1,13 @@
import std.stdio, std.algorithm, std.range, std.array;
auto forwardDifference(Range)(Range d, in int level) {
foreach (_; 0 .. level)
d = zip(d[1 .. $], d).map!q{ a[0] - a[1] }().array();
return d;
}
void main() {
auto data = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5];
foreach (level; 0 .. data.length)
writeln(forwardDifference(data, level));
}

View file

@ -0,0 +1,12 @@
import std.stdio;
T[] forwardDifference(T)(T[] s, in int n) pure {
foreach (_; 0 .. n)
s[] -= s[1 .. $];
return s[0 .. $ - n];
}
void main() {
immutable A = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5];
foreach (level; 0 .. A.length)
writeln(forwardDifference(A.dup, level));
}

View file

@ -0,0 +1,8 @@
import std.stdio, std.range;
void main() {
auto D = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5];
auto R = recurrence!q{(a[n-1].dup[] -= a[n-1][1..$])[0..$-1]}(D);
foreach (di; take(R, D.length))
writeln(di);
}