langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
18
Task/Matrix-transposition/Perl-6/matrix-transposition-1.pl6
Normal file
18
Task/Matrix-transposition/Perl-6/matrix-transposition-1.pl6
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
sub transpose(@m)
|
||||
{
|
||||
my @t;
|
||||
for ^@m X ^@m[0] -> $x, $y { @t[$y][$x] = @m[$x][$y] }
|
||||
return @t;
|
||||
}
|
||||
|
||||
# creates a random matrix
|
||||
my @a;
|
||||
for (^10).pick X (^10).pick -> $x, $y { @a[$x][$y] = (^100).pick; }
|
||||
|
||||
say "original: ";
|
||||
.perl.say for @a;
|
||||
|
||||
my @b = transpose(@a);
|
||||
|
||||
say "transposed: ";
|
||||
.perl.say for @b;
|
||||
10
Task/Matrix-transposition/Perl-6/matrix-transposition-2.pl6
Normal file
10
Task/Matrix-transposition/Perl-6/matrix-transposition-2.pl6
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
sub transpose (@m) {
|
||||
@m[0].keys.map: {[ @m».[$_] ]};
|
||||
}
|
||||
|
||||
my @a = [< a b c d e >],
|
||||
[< f g h i j >],
|
||||
[< k l m n o >],
|
||||
[< p q r s t >];
|
||||
|
||||
.say for @a.&transpose;
|
||||
Loading…
Add table
Add a link
Reference in a new issue