Anonymous user
Matrix transposition: Difference between revisions
Updated both D entries
(→{{header|Pascal}}: add example) |
(Updated both D entries) |
||
Line 646:
=={{header|D}}==
===Locally Procedural Style===
<lang d>import std.stdio, std.algorithm, std.array, std.conv;▼
<lang d>import std.stdio;
auto r = new
foreach (nr, row; m)
foreach (nc, c; row)
Line 661 ⟶ 662:
[18, 19, 20, 21]];
immutable T = transpose(M);
}</lang>
{{out}}
<pre>
===Functional
Same output.
▲<lang d>import std.stdio, std.algorithm, std.conv, std.range;
auto transpose(T)(in T[][] m) /*pure nothrow*/ {
return iota(m[0].length).map!(i => transversal(m, i))(
}
Line 680 ⟶ 682:
[18, 19, 20, 21]];
/*immutable*/ auto T = transpose(M);
}</lang>
|