Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
12
Task/Matrix-transposition/D/matrix-transposition-3.d
Normal file
12
Task/Matrix-transposition/D/matrix-transposition-3.d
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue