aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-08-25 14:45:23 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-08-25 14:45:23 +0100
commit3819d78c95a798bd0b50f00d3053908b81b796bf (patch)
tree66bcc9fda6fd10855781d268c6e39083d6ddb4e8
parent4e34955ba30fd8210e8b0bf199b47fe950c4bc3a (diff)
downloadperlweeklychallenge-club-3819d78c95a798bd0b50f00d3053908b81b796bf.tar.gz
perlweeklychallenge-club-3819d78c95a798bd0b50f00d3053908b81b796bf.tar.bz2
perlweeklychallenge-club-3819d78c95a798bd0b50f00d3053908b81b796bf.zip
Add Perl solution to challenge 254
-rw-r--r--challenge-254/paulo-custodio/Makefile2
-rw-r--r--challenge-254/paulo-custodio/perl/ch-1.pl31
-rw-r--r--challenge-254/paulo-custodio/perl/ch-2.pl31
-rw-r--r--challenge-254/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-254/paulo-custodio/t/test-2.yaml20
5 files changed, 99 insertions, 0 deletions
diff --git a/challenge-254/paulo-custodio/Makefile b/challenge-254/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-254/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-254/paulo-custodio/perl/ch-1.pl b/challenge-254/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..6789b429b5
--- /dev/null
+++ b/challenge-254/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+# Challenge 254
+#
+# Task 1: Three Power
+# Submitted by: Mohammad S Anwar
+# You are given a positive integer, $n.
+#
+# Write a script to return true if the given integer is a power of three
+# otherwise return false.
+#
+# Example 1
+# Input: $n = 27
+# Output: true
+#
+# 27 = 3 ^ 3
+# Example 2
+# Input: $n = 0
+# Output: true
+#
+# 0 = 0 ^ 3
+# Example 3
+# Input: $n = 6
+# Output: false
+
+use Modern::Perl;
+
+my $n = shift || 0;
+my $root = $n ** (1/3);
+my $have_root = (int($root) == $root);
+say $have_root ? 'true' : 'false';
diff --git a/challenge-254/paulo-custodio/perl/ch-2.pl b/challenge-254/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..8637ffc586
--- /dev/null
+++ b/challenge-254/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+# Challenge 254
+#
+# Task 2: Reverse Vowels
+# Submitted by: Mohammad S Anwar
+# You are given a string, $s.
+#
+# Write a script to reverse all the vowels (a, e, i, o, u) in the given string.
+#
+# Example 1
+# Input: $s = "Raku"
+# Output: "Ruka"
+# Example 2
+# Input: $s = "Perl"
+# Output: "Perl"
+# Example 3
+# Input: $s = "Julia"
+# Output: "Jaliu"
+# Example 4
+# Input: $s = "Uiua"
+# Output: "Auiu"
+
+use Modern::Perl;
+
+my $word = shift || "";
+my @vowels;
+$word =~ s/[aeiou]/ push @vowels, $&; $& /gei;
+$word =~ s/[aeiou]/ pop @vowels /gei;
+$word =~ s/(.)(.*)/ uc($1).lc($2) /e;
+say $word;
diff --git a/challenge-254/paulo-custodio/t/test-1.yaml b/challenge-254/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..19b49b312f
--- /dev/null
+++ b/challenge-254/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: 27
+ input:
+ output: true
+- setup:
+ cleanup:
+ args: 0
+ input:
+ output: true
+- setup:
+ cleanup:
+ args: 6
+ input:
+ output: false
diff --git a/challenge-254/paulo-custodio/t/test-2.yaml b/challenge-254/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..91791a52fd
--- /dev/null
+++ b/challenge-254/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,20 @@
+- setup:
+ cleanup:
+ args: Raku
+ input:
+ output: Ruka
+- setup:
+ cleanup:
+ args: Perl
+ input:
+ output: Perl
+- setup:
+ cleanup:
+ args: Julia
+ input:
+ output: Jaliu
+- setup:
+ cleanup:
+ args: Uiua
+ input:
+ output: Auiu