A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
17
Task/Matrix-transposition/D/matrix-transposition-1.d
Normal file
17
Task/Matrix-transposition/D/matrix-transposition-1.d
Normal 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);
|
||||
}
|
||||
13
Task/Matrix-transposition/D/matrix-transposition-2.d
Normal file
13
Task/Matrix-transposition/D/matrix-transposition-2.d
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue