aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE7-87-83 <fungcheokyin@gmail.com>2024-06-29 06:26:08 +0800
committerE7-87-83 <fungcheokyin@gmail.com>2024-06-29 06:26:08 +0800
commit6c6cc20bd8ba2af01da474bacf7d54c300cb64df (patch)
tree5cff1695340cff5b23991ed35903926e71e31e68
parent63dc85670a33c9d081fa9764fff45df4e0fbaeed (diff)
downloadperlweeklychallenge-club-6c6cc20bd8ba2af01da474bacf7d54c300cb64df.tar.gz
perlweeklychallenge-club-6c6cc20bd8ba2af01da474bacf7d54c300cb64df.tar.bz2
perlweeklychallenge-club-6c6cc20bd8ba2af01da474bacf7d54c300cb64df.zip
Week 275
-rwxr-xr-xchallenge-275/cheok-yin-fung/perl/ch-1.pl28
-rwxr-xr-xchallenge-275/cheok-yin-fung/perl/ch-2.pl33
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-275/cheok-yin-fung/perl/ch-1.pl b/challenge-275/cheok-yin-fung/perl/ch-1.pl
new file mode 100755
index 0000000000..43f8d5c28f
--- /dev/null
+++ b/challenge-275/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,28 @@
+# The Weekly Challenge 275
+# Task 1 Broken Keys
+use v5.30.0;
+use warnings;
+
+sub bro_k {
+ my $sentence = $_[0];
+ my @words = split " ", $sentence;
+ our @keys = map {lc $_} $_[1]->@*;
+ my $ans = 0;
+ sub typable {
+ my $w = lc $_[0];
+ for my $k (@keys) {
+ return 0 if index($w,$k)>=0;
+ }
+ return 1;
+ }
+ for my $word (@words) {
+ $ans++ if typable($word);
+ }
+ return $ans;
+}
+
+use Test::More tests=>4;
+ok bro_k("Perl Weekly Challenge", ['l', 'a']) == 0;
+ok bro_k("Perl and Raku", ['a']) == 1;
+ok bro_k("Well done Team PWC", ['l','o']) == 2;
+ok bro_k("The joys of polyglottism", ['T']) == 2;
diff --git a/challenge-275/cheok-yin-fung/perl/ch-2.pl b/challenge-275/cheok-yin-fung/perl/ch-2.pl
new file mode 100755
index 0000000000..d12cb756a5
--- /dev/null
+++ b/challenge-275/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,33 @@
+# The Weekly Challenge 275
+# Task 2 Replace Digits
+use v5.30.0;
+use warnings;
+
+sub rd {
+ my $str = $_[0];
+ my @arr = split "", $str;
+ my $pre_c = $arr[0];
+ for my $i (1..$#arr) {
+ if ($arr[$i] =~ /[a-z]/) {
+ $pre_c = $arr[$i];
+ next;
+ }
+ if ($arr[$i] =~ /\d/) {
+ my $num = $arr[$i];
+ my $the_a = ($pre_c eq lc $pre_c) ? 'a' : 'A';
+ $arr[$i] =
+ chr(ord($the_a) + (ord($pre_c)-ord($the_a)+$num) % 26);
+ }
+ }
+ say(join "", @arr);
+ return join "", @arr;
+}
+
+use Test::More tests=>7;
+ok rd('a1c1e1') eq 'abcdef';
+ok rd('a1b2c3d4') eq 'abbdcfdh';
+ok rd('b2b') eq 'bdb';
+ok rd('a16z') eq 'abgz';
+ok rd('a0') eq 'aa';
+ok rd('Z1') eq 'ZA';
+ok rd('abc') eq 'abc';