From 0f7894a1028e3513210b613ac18afe491b564abb Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Sun, 2 Jan 2022 22:21:37 +0000 Subject: Task 1 --- challenge-145/perlboy1967/ch-1.pl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 challenge-145/perlboy1967/ch-1.pl 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); + -- cgit