aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-240/cheok-yin-fung/perl/ch-1.pl15
-rw-r--r--challenge-240/cheok-yin-fung/perl/ch-2.pl16
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-240/cheok-yin-fung/perl/ch-1.pl b/challenge-240/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..9c81edc391
--- /dev/null
+++ b/challenge-240/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,15 @@
+# The Weekly Challenge 240
+# Task 1 Acronym
+use v5.30.0;
+use warnings;
+
+sub ac {
+ my @str = $_[0]->@*;
+ my $chk = $_[1];
+ return (join "", map { lc substr($_, 0, 1) } @str) eq lc $chk;
+}
+
+use Test::More tests=>3;
+ok ac(["Perl", "Python", "Pascal"], "ppp");
+ok !ac(["Perl", "Raku"], "rp");
+ok ac(["Oracle", "Awk", "C"], "oac");
diff --git a/challenge-240/cheok-yin-fung/perl/ch-2.pl b/challenge-240/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..0da5624712
--- /dev/null
+++ b/challenge-240/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,16 @@
+# The Weekly Challenge 240
+# Task 2 Build Array
+use v5.30.0;
+use warnings;
+
+sub ba {
+ my @int = @_;
+ my @new = map {$int[$int[$_]]} (0..$#int);
+ return [@new];
+}
+
+use Test::More tests=>2;
+use Test::Deep;
+
+cmp_deeply ba(0, 2, 1, 5, 3, 4), [0, 1, 2, 4, 5, 3];
+cmp_deeply ba(5, 0, 1, 2, 3, 4), [4, 5, 0, 1, 2, 3];