aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2020-11-23 15:04:44 +0100
committerJörg Sommrey <28217714+jo-37@users.noreply.github.com>2020-11-25 17:36:28 +0100
commit0de3c77ff03f11cff94be7f91ad134bcf9ffcb36 (patch)
treecad2eb0ffaedb01ce80e98efe24b36202d0f4ac4
parent89360d10a5f2c28dfaa7524a737129ebe9dbd23a (diff)
downloadperlweeklychallenge-club-0de3c77ff03f11cff94be7f91ad134bcf9ffcb36.tar.gz
perlweeklychallenge-club-0de3c77ff03f11cff94be7f91ad134bcf9ffcb36.tar.bz2
perlweeklychallenge-club-0de3c77ff03f11cff94be7f91ad134bcf9ffcb36.zip
Solution to task 1
-rwxr-xr-xchallenge-088/jo-37/perl/ch-1.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-088/jo-37/perl/ch-1.pl b/challenge-088/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..5225a6c847
--- /dev/null
+++ b/challenge-088/jo-37/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use Test2::V0;
+use List::Util 'product';
+
+sub prod_arr {
+ my $prod = product @_;
+ die "invalid data" unless $prod;
+
+ map $prod / $_, @_
+}
+
+is [prod_arr 5, 2, 1, 4, 3], [24, 60, 120, 30, 40], 'Example 1';
+is [prod_arr 2, 1, 4, 3], [12, 24, 6, 8], 'Example 2';
+like dies {prod_arr 2, 1, 0}, qr/^invalid data/,
+ 'zero is not a positive integer';
+is [prod_arr 2, -5, 3], [-15, 6, -10], 'negative numbers are ok, though';
+
+done_testing;