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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import std.stdio, std.algorithm, std.range, std.array;
|
||||
|
||||
auto forwardDifference(Range)(Range d, in int level) {
|
||||
auto forwardDifference(Range)(Range d, in int level) pure {
|
||||
foreach (immutable _; 0 .. level)
|
||||
d = d.zip(d.dropOne).map!(a => a[0] - a[1]).array;
|
||||
return d;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import std.stdio;
|
||||
|
||||
T[] forwardDifference(T)(T[] s, in int n) pure {
|
||||
foreach (_; 0 .. n)
|
||||
s[] -= s[1 .. $];
|
||||
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];
|
||||
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));
|
||||
foreach (immutable level; 0 .. A.length)
|
||||
forwardDifference(A.dup, level).writeln;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import std.stdio, std.range;
|
||||
|
||||
void main() {
|
||||
import std.stdio, std.range;
|
||||
|
||||
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);
|
||||
writefln("%(%s\n%)",
|
||||
recurrence!q{ (a[n - 1][0 .. $ - 1] =
|
||||
a[n - 1][1 .. $] -
|
||||
a[n - 1][0 .. $ - 1])[0 .. $] }(D)
|
||||
.take(D.length));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue