Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,20 +1,19 @@
|
|||
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;
|
||||
}
|
||||
in {
|
||||
assert(level >= 0 && level < data.length);
|
||||
} body {
|
||||
auto result = data.dup;
|
||||
foreach (immutable i; 0 .. level)
|
||||
foreach (immutable 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));
|
||||
import std.stdio;
|
||||
|
||||
const data = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5];
|
||||
foreach (immutable level; 0 .. data.length)
|
||||
forwardDifference(data, level).writeln;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue