aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-198/cheok-yin-fung/perl/ch-1.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-198/cheok-yin-fung/perl/ch-1.pl b/challenge-198/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..43bfd8a1c2
--- /dev/null
+++ b/challenge-198/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,19 @@
+# The Weekly Challenge 198
+# Task 1 Max Gap
+
+use v5.30.0;
+use warnings;
+use List::Util qw/max/;
+use List::MoreUtils qw/slide/;
+
+sub mg {
+ my @list = @_;
+ return 0 if scalar @list == 1;
+ my @slided = slide {$b-$a} @list;
+ my $max = max @slided;
+ return scalar grep {$max == $_} @slided;
+}
+
+use Test::More tests=>2;
+ok mg(1,2,5,8) == 2;
+ok mg(3) == 0;