aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-01-03 01:27:16 +0000
committerGitHub <noreply@github.com>2022-01-03 01:27:16 +0000
commit36aa1d8753c595c4178b979b841bd9f8ef7e7ee4 (patch)
treec02037ba72ed26615121e0310823d4153e669ae3
parentc028030a69d2e015a9b29fa6137e80e2a055e1d9 (diff)
parent0f7894a1028e3513210b613ac18afe491b564abb (diff)
downloadperlweeklychallenge-club-36aa1d8753c595c4178b979b841bd9f8ef7e7ee4.tar.gz
perlweeklychallenge-club-36aa1d8753c595c4178b979b841bd9f8ef7e7ee4.tar.bz2
perlweeklychallenge-club-36aa1d8753c595c4178b979b841bd9f8ef7e7ee4.zip
Merge pull request #5449 from PerlBoy1967/branch-for-challenge-145
Task 1
-rwxr-xr-xchallenge-145/perlboy1967/ch-1.pl37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-145/perlboy1967/ch-1.pl b/challenge-145/perlboy1967/ch-1.pl
new file mode 100755
index 0000000000..a253271018
--- /dev/null
+++ b/challenge-145/perlboy1967/ch-1.pl
@@ -0,0 +1,37 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 145
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-145/#TASK1
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #1 › Dot Product
+Submitted by: Mohammad S Anwar
+
+You are given 2 arrays of same size, @a and @b.
+
+Write a script to implement Dot Product.
+
+=cut
+
+use v5.16;
+use strict;
+use warnings;
+
+use List::Util qw(sum);
+use List::MoreUtils qw(pairwise);
+
+sub dotProduct(\@\@) {
+ my ($c,$d) = @_;
+ no warnings 'once';
+ return sum pairwise{$a*$b}@$c,@$d;
+}
+
+my @a = (1,2,3);
+my @b = (2,3,4);
+
+printf "dotProduct of (%s) and (%s) = %d\n",
+ join(',',@a), join(',',@b), dotProduct(@a,@b);
+