aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-204/cheok-yin-fung/perl/ch-1.pl17
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-204/cheok-yin-fung/perl/ch-1.pl b/challenge-204/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..d59c1bcc0f
--- /dev/null
+++ b/challenge-204/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,17 @@
+# The Weekly Challenge 204
+# Task 1 Monotonic Array
+use v5.30.0;
+use warnings;
+use List::Util qw/all/;
+use List::MoreUtils qw/slide/;
+
+sub ma {
+ my @arr = @_;
+ return (all {$_ >= 0} slide {$a-$b} @arr)
+ || (all {$_ <= 0} slide {$a-$b} @arr);
+}
+
+use Test::More tests=>3;
+ok ma(1,2,2,3) == 1;
+ok ma(1,3,2) == 0;
+ok ma(6,5,5,4) == 1;