aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-31 13:03:39 +0000
committerGitHub <noreply@github.com>2024-01-31 13:03:39 +0000
commit233588c3a15107cf8e5ad35a7bdcd3534ae2242f (patch)
tree6a667cf28a8270c6b656fb76fe099659ee014086
parent4099837cf3689e1d78a66905fde9c5a45ff95940 (diff)
parent959647373fe8b2e4626d37ea01ef68e470c8e9f9 (diff)
downloadperlweeklychallenge-club-233588c3a15107cf8e5ad35a7bdcd3534ae2242f.tar.gz
perlweeklychallenge-club-233588c3a15107cf8e5ad35a7bdcd3534ae2242f.tar.bz2
perlweeklychallenge-club-233588c3a15107cf8e5ad35a7bdcd3534ae2242f.zip
Merge pull request #9481 from choroba/ech254
Add solutions to 254: Three Power & Reverse Vowels by E. Choroba
-rwxr-xr-xchallenge-254/e-choroba/perl/ch-1.pl20
-rwxr-xr-xchallenge-254/e-choroba/perl/ch-2.pl20
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-254/e-choroba/perl/ch-1.pl b/challenge-254/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..0920ddf653
--- /dev/null
+++ b/challenge-254/e-choroba/perl/ch-1.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub three_power($n) {
+ for (1, 2) {
+ return if $n % 3;
+ $n /= 3;
+ }
+ return 1
+}
+
+use Test::More tests => 3 + 2;
+
+ok three_power(27), 'Example 1';
+ok three_power(0), 'Example 2';
+ok ! three_power(6), 'Example 3';
+ok three_power(18446703239944862784), 'Large true';
+ok ! three_power(18446744073709551615), 'Large false';
diff --git a/challenge-254/e-choroba/perl/ch-2.pl b/challenge-254/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..11c56a1804
--- /dev/null
+++ b/challenge-254/e-choroba/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub reverse_vowels($s) {
+ my @vowels = $s =~ /[aeiou]/gi;
+ $s =~ s{([aeiou])}{
+ my $v = pop @vowels;
+ $1 ge 'a' ? lc $v : uc $v
+ }ige;
+ return $s
+}
+
+use Test::More tests => 4;
+
+is reverse_vowels('Raku'), 'Ruka', 'Example 1';
+is reverse_vowels('Perl'), 'Perl', 'Example 2';
+is reverse_vowels('Julia'), 'Jaliu', 'Example 3';
+is reverse_vowels('Uiua'), 'Auiu', 'Example 4';