RosettaCodeData/Task/Forward-difference/D/forward-difference-3.d

13 lines
380 B
D
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
import std.stdio;
2015-02-20 00:35:01 -05:00
T[] forwardDifference(T)(T[] s, in int n) pure nothrow @nogc {
foreach (immutable i; 0 .. n)
s[0 .. $ - i - 1] = s[1 .. $ - i] - s[0 .. $ - i - 1];
2013-04-10 21:29:02 -07:00
return s[0 .. $ - n];
}
void main() {
immutable A = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5];
2015-02-20 00:35:01 -05:00
foreach (immutable level; 0 .. A.length)
forwardDifference(A.dup, level).writeln;
2013-04-10 21:29:02 -07:00
}