This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,17 @@
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);
}

View file

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