aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-250/cheok-yin-fung/perl/ch-1.pl17
-rw-r--r--challenge-250/cheok-yin-fung/perl/ch-2.pl22
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-250/cheok-yin-fung/perl/ch-1.pl b/challenge-250/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..8316c395ee
--- /dev/null
+++ b/challenge-250/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,17 @@
+# The Weekly Challenge 250
+# Task 1 Smallest Index
+use v5.30.0;
+use warnings;
+
+sub si {
+ my @arr = @_;
+ for my $k (0..$#arr) {
+ return $k if $k == $arr[$k] % 10;
+ }
+ return -1;
+}
+
+use Test::More tests=>3;
+ok si(0, 1, 2) == 0;
+ok si(4, 3, 2, 1) == 2;
+ok si(1, 2, 3, 4, 5, 6, 7, 8, 9, 0) == -1;
diff --git a/challenge-250/cheok-yin-fung/perl/ch-2.pl b/challenge-250/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..729e601156
--- /dev/null
+++ b/challenge-250/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,22 @@
+# The Weekly Challenge 250
+# Task 2 Alphanumeric String Value
+use v5.30.0;
+use warnings;
+use List::Util qw/max/;
+
+sub asv {
+ my $word = $_[0];
+ return $1 if $word =~ /^0*(\d+)$/;
+ return length $word;
+}
+
+sub masv {
+ my @arr = @_;
+ return max map {asv $_} @arr;
+}
+
+
+use Test2::V0;
+ok masv("perl", "2", "000", "python", "r4ku") == 6;
+ok masv("001", "1", "000", "0001") == 1;
+done_testing();