diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2022-01-02 22:21:37 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2022-01-02 22:21:37 +0000 |
| commit | 0f7894a1028e3513210b613ac18afe491b564abb (patch) | |
| tree | 266311690ec0aa3e70b5ff1335cfaf1421379d6a | |
| parent | b3bd78828c9c0a169173683255a1bf92b6f3c0e8 (diff) | |
| download | perlweeklychallenge-club-0f7894a1028e3513210b613ac18afe491b564abb.tar.gz perlweeklychallenge-club-0f7894a1028e3513210b613ac18afe491b564abb.tar.bz2 perlweeklychallenge-club-0f7894a1028e3513210b613ac18afe491b564abb.zip | |
Task 1
| -rwxr-xr-x | challenge-145/perlboy1967/ch-1.pl | 37 |
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); + |
