aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE7-87-83 <fungcheokyin@gmail.com>2024-08-18 23:23:05 +0800
committerE7-87-83 <fungcheokyin@gmail.com>2024-08-18 23:23:05 +0800
commitddc0de5056fd4516e471c350d054b5c46e113202 (patch)
tree5d787978eb74690ebf5c17f85ff5fe9799b402ce
parentc9df02e64b0a556213eeeb8c673dc882162afa88 (diff)
downloadperlweeklychallenge-club-ddc0de5056fd4516e471c350d054b5c46e113202.tar.gz
perlweeklychallenge-club-ddc0de5056fd4516e471c350d054b5c46e113202.tar.bz2
perlweeklychallenge-club-ddc0de5056fd4516e471c350d054b5c46e113202.zip
Week 282
-rw-r--r--challenge-282/cheok-yin-fung/perl/ch-1.pl15
-rw-r--r--challenge-282/cheok-yin-fung/perl/ch-2.pl18
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-282/cheok-yin-fung/perl/ch-1.pl b/challenge-282/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..29083e409e
--- /dev/null
+++ b/challenge-282/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,15 @@
+# The Weekly Challenge 282
+# Task 1 Good Integer
+use v5.30.0;
+use warnings;
+
+sub gi {
+ my $int = $_[0];
+ return -1 if $int =~ /(\d)\1\1\1/;
+ return $1 x 3 if $int =~ /(\d)\1\1/;
+}
+
+use Test::More tests=>3;
+ok gi("12344456") eq "444";
+ok gi("1233334") eq -1;
+ok gi("1020003") eq "000";
diff --git a/challenge-282/cheok-yin-fung/perl/ch-2.pl b/challenge-282/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..276e97afb5
--- /dev/null
+++ b/challenge-282/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,18 @@
+# The Weekly Challenge 282
+# Task 2 Changing Keys
+use v5.30.0;
+use warnings;
+use List::Util qw/reduce/;
+
+sub ck {
+ my $str = $_[0];
+ $str = lc $str;
+ my @alphabets = split "", $str;
+ my $abc = reduce { substr($a,-1) eq $b ? $a : $a.$b } @alphabets;
+ return ((length $abc) - 1);
+}
+
+use Test::More tests=>3;
+ok ck("pPeERrLl") == 3;
+ok ck("rRr") == 0;
+ok ck("GoO") == 1;