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,17 +1,8 @@
import std.stdio;
T[][] transpose(T)(immutable /*in*/ T[][] m) pure nothrow {
auto r = new typeof(return)(m[0].length, m.length);
foreach (nr, row; m)
foreach (nc, c; row)
r[nc][nr] = c;
return r;
}
void main() {
immutable M = [[10, 11, 12, 13],
[14, 15, 16, 17],
[18, 19, 20, 21]];
immutable T = transpose(M);
writefln("%(%(%2d %)\n%)", T);
import std.stdio, std.range;
/*immutable*/ auto M = [[10, 11, 12, 13],
[14, 15, 16, 17],
[18, 19, 20, 21]];
writefln("%(%(%2d %)\n%)", M.transposed);
}

View file

@ -1,13 +1,16 @@
import std.stdio, std.algorithm, std.range;
auto transpose(T)(in T[][] m) /*pure nothrow*/ {
return m[0].length.iota.map!(i => m.transversal(i));
T[][] transpose(T)(in T[][] m) pure nothrow {
auto r = new typeof(return)(m[0].length, m.length);
foreach (immutable nr, const row; m)
foreach (immutable nc, immutable c; row)
r[nc][nr] = c;
return r;
}
void main() {
import std.stdio;
immutable M = [[10, 11, 12, 13],
[14, 15, 16, 17],
[18, 19, 20, 21]];
/*immutable*/ auto T = M.transpose;
writefln("%(%(%2d %)\n%)", T);
writefln("%(%(%2d %)\n%)", M.transpose);
}

View file

@ -0,0 +1,12 @@
import std.stdio, std.algorithm, std.range, std.functional;
auto transpose(T)(in T[][] m) pure nothrow {
return m[0].length.iota.map!(curry!(transversal, m));
}
void main() {
immutable M = [[10, 11, 12, 13],
[14, 15, 16, 17],
[18, 19, 20, 21]];
writefln("%(%(%2d %)\n%)", M.transpose);
}