Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,13 +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();
foreach (immutable _; 0 .. level)
d = d.zip(d.dropOne).map!(a => 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));
const data = [90.5, 47, 58, 29, 22, 32, 55, 5, 55, 73.5];
foreach (immutable level; 0 .. data.length)
forwardDifference(data, level).writeln;
}

View file

@ -0,0 +1 @@
ndiff(A, n::Integer) = n < 1 ? A : diff(ndiff(A, n-1))

View file

@ -0,0 +1,13 @@
julia> s = [90, 47, 58, 29, 22, 32, 55, 5, 55, 73]
julia> [ndiff(s, i) for i in 0:9]
10-element Array{Any,1}:
[90,47,58,29,22,32,55,5,55,73]
[-43,11,-29,-7,10,23,-50,50,18]
[54,-40,22,17,13,-73,100,-32]
[-94,62,-5,-4,-86,173,-132]
[156,-67,1,-82,259,-305]
[-223,68,-83,341,-564]
[291,-151,424,-905]
[-442,575,-1329]
[1017,-1904]
[-2921]