aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-02-03 10:38:37 +0000
committerGitHub <noreply@github.com>2024-02-03 10:38:37 +0000
commit1091ad3a12ccd9798f81855a6735e0084160c076 (patch)
tree39683c4dce511ced45803035517da84ebbcf26e7
parent5e224c8e3dd0d5cd02436fd97337c9ac8add03e8 (diff)
parentf82ffa553ea432e6b22b069cd47f9276a45b052c (diff)
downloadperlweeklychallenge-club-1091ad3a12ccd9798f81855a6735e0084160c076.tar.gz
perlweeklychallenge-club-1091ad3a12ccd9798f81855a6735e0084160c076.tar.bz2
perlweeklychallenge-club-1091ad3a12ccd9798f81855a6735e0084160c076.zip
Merge pull request #9508 from simongreen-net/master
Simon's solution to challenge 254
-rw-r--r--challenge-254/sgreen/README.md4
-rw-r--r--challenge-254/sgreen/blog.txt1
-rwxr-xr-xchallenge-254/sgreen/perl/ch-1.pl19
-rwxr-xr-xchallenge-254/sgreen/perl/ch-2.pl26
-rwxr-xr-xchallenge-254/sgreen/python/ch-1.py23
-rwxr-xr-xchallenge-254/sgreen/python/ch-2.py31
-rwxr-xr-xchallenge-254/sgreen/python/test.py22
7 files changed, 124 insertions, 2 deletions
diff --git a/challenge-254/sgreen/README.md b/challenge-254/sgreen/README.md
index 4f9fe5e116..8963a142f3 100644
--- a/challenge-254/sgreen/README.md
+++ b/challenge-254/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 253
+# The Weekly Challenge 254
-Blog: [The weakest split](https://dev.to/simongreennet/the-weakest-split-5ad7)
+Blog: [Power to the vowels](https://dev.to/simongreennet/power-to-the-vowels-5cdp)
diff --git a/challenge-254/sgreen/blog.txt b/challenge-254/sgreen/blog.txt
new file mode 100644
index 0000000000..d436040f1b
--- /dev/null
+++ b/challenge-254/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/power-to-the-vowels-5cdp \ No newline at end of file
diff --git a/challenge-254/sgreen/perl/ch-1.pl b/challenge-254/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..2b51cd8203
--- /dev/null
+++ b/challenge-254/sgreen/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use Math::Round 'round';
+
+sub three_power ($n) {
+ # Get the closest integer to a cube root
+ my $i = round(abs($n) ** (1/3));
+
+ # Return true if this number is indeed a cube root
+ return $i ** 3 == abs($n);
+}
+
+my $r = three_power($ARGV[0]);
+say $r ? 'true' : 'false'; \ No newline at end of file
diff --git a/challenge-254/sgreen/perl/ch-2.pl b/challenge-254/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..78feee1f3d
--- /dev/null
+++ b/challenge-254/sgreen/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub reverse_vowels ($s) {
+ # Convert it to lower case
+ $s = lc $s;
+
+ # Extract the vowels
+ my @vowel_list = grep { /[aeiou]/ } split //, $s;
+
+ for my $pos ( 0 .. length($s) - 1 ) {
+ # If the character here is a vowel
+ if ( substr( $s, $pos, 1 ) =~ /[aeiou]/ ) {
+ # ... get the last vowel
+ substr( $s, $pos, 1 ) = pop(@vowel_list);
+ }
+ }
+
+ return ucfirst $s;
+}
+
+say reverse_vowels($ARGV[0]); \ No newline at end of file
diff --git a/challenge-254/sgreen/python/ch-1.py b/challenge-254/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..37c492575d
--- /dev/null
+++ b/challenge-254/sgreen/python/ch-1.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def three_power(n: int) -> bool:
+ # Get the closest integer to a cube root
+ i = round(abs(n) ** (1/3))
+
+ # Return true if this number is indeed a cube root
+ return i ** 3 == abs(n)
+
+
+def main():
+ # Convert input into integers
+ n = int(sys.argv[1])
+ result = three_power(n)
+ print('true' if result else 'false')
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ main()
diff --git a/challenge-254/sgreen/python/ch-2.py b/challenge-254/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..eed9768157
--- /dev/null
+++ b/challenge-254/sgreen/python/ch-2.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def reverse_vowels(s: str) -> str:
+ # Convert it to lower case
+ s = s.lower()
+
+ # Extract the vowels
+ vowel_list = [c for c in s if c in 'aeiou']
+
+ new_string = ''
+ for c in s:
+ # If the character here is a vowel
+ if c in 'aeiou':
+ # ... get the last vowel
+ new_string += vowel_list.pop()
+ else:
+ new_string += c
+
+ return new_string.capitalize()
+
+
+def main():
+ s = sys.argv[1]
+ print(reverse_vowels(s))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/challenge-254/sgreen/python/test.py b/challenge-254/sgreen/python/test.py
new file mode 100755
index 0000000000..f9d9c15650
--- /dev/null
+++ b/challenge-254/sgreen/python/test.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+import unittest
+ch_1 = __import__('ch-1')
+ch_2 = __import__('ch-2')
+
+
+class TestClass(unittest.TestCase):
+ def test_ch_1(self):
+ self.assertTrue(ch_1.three_power(27))
+ self.assertTrue(ch_1.three_power(0))
+ self.assertFalse(ch_1.three_power(6))
+
+ def test_ch_2(self):
+ self.assertEqual(ch_2.reverse_vowels('Raku'), 'Ruka')
+ self.assertEqual(ch_2.reverse_vowels('Perl'), 'Perl')
+ self.assertEqual(ch_2.reverse_vowels('Julia'), 'Jaliu')
+ self.assertEqual(ch_2.reverse_vowels('Uiua'), 'Auiu')
+
+
+if __name__ == '__main__':
+ unittest.main()