aboutsummaryrefslogtreecommitdiff
path: root/challenge-254
diff options
context:
space:
mode:
authorCY Fung <fungcheokyin@gmail.com>2024-02-12 05:21:35 +0800
committerCY Fung <fungcheokyin@gmail.com>2024-02-12 05:21:35 +0800
commit0c0f465a0a069024148709388c24b173a6cb26e8 (patch)
treeb474ba50deca4191b78c32632820ee389dc69e70 /challenge-254
parent33dcd8be189e911df40a39fa97f481f02c06bd84 (diff)
downloadperlweeklychallenge-club-0c0f465a0a069024148709388c24b173a6cb26e8.tar.gz
perlweeklychallenge-club-0c0f465a0a069024148709388c24b173a6cb26e8.tar.bz2
perlweeklychallenge-club-0c0f465a0a069024148709388c24b173a6cb26e8.zip
Week 255, and add Task 2 of the missed Week 254
Diffstat (limited to 'challenge-254')
-rw-r--r--challenge-254/cheok-yin-fung/ch-2.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-254/cheok-yin-fung/ch-2.pl b/challenge-254/cheok-yin-fung/ch-2.pl
new file mode 100644
index 0000000000..307101ff7b
--- /dev/null
+++ b/challenge-254/cheok-yin-fung/ch-2.pl
@@ -0,0 +1,35 @@
+# The Weekly Challenge 254
+# Task 2 Reverse Vowels
+use v5.30.0;
+use warnings;
+
+sub r_v {
+ my $s = $_[0];
+ my $c_s = $s;
+ $c_s =~ tr/aeiou/=/;
+ $c_s =~ tr/AEIOU/_/;
+ my @arr = split "", $s;
+ my @c_arr = split "", $c_s;
+ my @vowels = reverse map {lc} grep { /[aeiou]/i} @arr;
+ my $i = 0;
+ for my $j (0..$#c_arr) {
+ my $c = $c_arr[$j];
+ if ($c eq "=") {
+ $arr[$j] = $vowels[$i];
+ $i++;
+ }
+ if ($c eq "_") {
+ $arr[$j] = uc $vowels[$i];
+ $i++;
+ }
+ }
+ return join "", @arr;
+}
+
+use Test::More tests=>5;
+ok r_v("Raku") eq "Ruka";
+ok r_v("Perl") eq "Perl";
+ok r_v("Julia") eq "Jaliu";
+ok r_v("Uiua") eq "Auiu";
+ok r_v("Cpp") eq "Cpp";
+