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

13 lines
382 B
D
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
import std.stdio;
2026-04-30 12:34:36 -04:00
T[] forwardDifference(T)(T[] s, in ulong n) pure nothrow @nogc {
2023-07-01 11:58:00 -04:00
foreach (immutable i; 0 .. n)
s[0 .. $ - i - 1] = s[1 .. $ - i] - s[0 .. $ - i - 1];
return s[0 .. $ - n];
}
void main() {
immutable A = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5];
foreach (immutable level; 0 .. A.length)
forwardDifference(A.dup, level).writeln;
}