diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-12-30 00:38:53 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-12-30 00:38:53 +0000 |
| commit | ae245c6e7927f8c954e5d318ea9be2406b07206b (patch) | |
| tree | 3cbd43b8bce071fc5d1059e0528745e48a401761 /challenge-145 | |
| parent | d70f4d0ef91fbc1bdf6b966c812db2de7020f4c0 (diff) | |
| download | perlweeklychallenge-club-ae245c6e7927f8c954e5d318ea9be2406b07206b.tar.gz perlweeklychallenge-club-ae245c6e7927f8c954e5d318ea9be2406b07206b.tar.bz2 perlweeklychallenge-club-ae245c6e7927f8c954e5d318ea9be2406b07206b.zip | |
- Added Raku solution to the task "Dot Product" of week 145.
Diffstat (limited to 'challenge-145')
| -rw-r--r-- | challenge-145/mohammad-anwar/raku/ch-1.raku | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-145/mohammad-anwar/raku/ch-1.raku b/challenge-145/mohammad-anwar/raku/ch-1.raku new file mode 100644 index 0000000000..0df4f11e1a --- /dev/null +++ b/challenge-145/mohammad-anwar/raku/ch-1.raku @@ -0,0 +1,37 @@ +#!/usr/bin/env raku + +=begin pod + +Week 145: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-145 + +Task #1: Dot Product + + You are given 2 arrays of same size, @a and @b. + + Write a script to implement Dot Product. + +=end pod + +use Test; + +is dot-product([1,2,3], [4,5,6]), 32, 'Example'; + +done-testing; + +# +# +# METHODS + +sub dot-product($a, $b --> Int) { + + if $a.elems == $b.elems { + my Int $dp = 0; + for 0 .. $a.elems-1 -> $i { + $dp += $a[$i] * $b[$i]; + } + + return $dp; + } +} |
