aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;