Anonymous user
Matrix transposition: Difference between revisions
Updated D code
(→{{header|Go}}: added version with flat representation) |
(Updated D code) |
||
Line 655:
<lang d>import std.stdio, std.algorithm, std.array, std.conv;
auto transpose(T)(immutable /*in*/ T[][] m) pure nothrow {
auto r = new T[][](m[0].length, m.length);
foreach (nr, row; m)
Line 664:
void main() {
[14, 15, 16, 17],
[18, 19, 20, 21]];
writeln("[",
}</lang>
Output:
Line 678:
<lang d>import std.stdio, std.algorithm, std.conv, std.range;
auto transpose(T)(in T[][] m) /*pure nothrow*/ {
return map!
}
Line 687:
[18, 19, 20, 21]];
/*immutable*/ auto T = transpose(M);
writeln("[",
}</lang>
|