Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
35
Task/Matrix-multiplication/Perl/matrix-multiplication.pl
Normal file
35
Task/Matrix-multiplication/Perl/matrix-multiplication.pl
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
sub mmult
|
||||
{
|
||||
our @a; local *a = shift;
|
||||
our @b; local *b = shift;
|
||||
my @p = [];
|
||||
my $rows = @a;
|
||||
my $cols = @{ $b[0] };
|
||||
my $n = @b - 1;
|
||||
for (my $r = 0 ; $r < $rows ; ++$r)
|
||||
{
|
||||
for (my $c = 0 ; $c < $cols ; ++$c)
|
||||
{
|
||||
$p[$r][$c] += $a[$r][$_] * $b[$_][$c]
|
||||
foreach 0 .. $n;
|
||||
}
|
||||
}
|
||||
return [@p];
|
||||
}
|
||||
|
||||
sub display { join("\n" => map join(" " => map(sprintf("%4d", $_), @$_)), @{+shift})."\n" }
|
||||
|
||||
@a =
|
||||
(
|
||||
[1, 2],
|
||||
[3, 4]
|
||||
);
|
||||
|
||||
@b =
|
||||
(
|
||||
[-3, -8, 3],
|
||||
[-2, 1, 4]
|
||||
);
|
||||
|
||||
$c = mmult(\@a,\@b);
|
||||
display($c)
|
||||
Loading…
Add table
Add a link
Reference in a new issue