aboutsummaryrefslogtreecommitdiff
path: root/challenge-254
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2024-01-29 17:28:30 -0500
committerDave Jacoby <jacoby.david@gmail.com>2024-01-29 17:28:30 -0500
commit2a9e94d7b06c5b07b142183d0c0131372be5b1cb (patch)
treea539825415416563b4a327ae8b9247874adf32c2 /challenge-254
parent4099837cf3689e1d78a66905fde9c5a45ff95940 (diff)
downloadperlweeklychallenge-club-2a9e94d7b06c5b07b142183d0c0131372be5b1cb.tar.gz
perlweeklychallenge-club-2a9e94d7b06c5b07b142183d0c0131372be5b1cb.tar.bz2
perlweeklychallenge-club-2a9e94d7b06c5b07b142183d0c0131372be5b1cb.zip
Blogged 254
Diffstat (limited to 'challenge-254')
-rw-r--r--challenge-254/dave-jacoby/blog.txt1
-rw-r--r--challenge-254/dave-jacoby/perl/ch-1.pl22
-rw-r--r--challenge-254/dave-jacoby/perl/ch-2.pl37
3 files changed, 60 insertions, 0 deletions
diff --git a/challenge-254/dave-jacoby/blog.txt b/challenge-254/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..a0f3bee2cb
--- /dev/null
+++ b/challenge-254/dave-jacoby/blog.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2024/01/29/reverse_vowelsweekly-challenge-eq-weekly-challenge-weekly-challenge-254.html
diff --git a/challenge-254/dave-jacoby/perl/ch-1.pl b/challenge-254/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..b49f2eb71d
--- /dev/null
+++ b/challenge-254/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+my @examples = ( 27, 0, 6 );
+
+for my $example (@examples) {
+ my $output = three_power($example);
+ say $output;
+
+ say <<~"END";
+ Input: \$n = $example
+ Output: $output
+ END
+}
+
+sub three_power ($input) {
+ my $cuberoot= $input ** (1/3);
+ return ( $cuberoot == int $cuberoot ) ? 'true' : 'false';
+}
diff --git a/challenge-254/dave-jacoby/perl/ch-2.pl b/challenge-254/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..f0e98c0c9b
--- /dev/null
+++ b/challenge-254/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use List::Util qw{ max sum0 };
+
+my @examples = ( "Raku", "Perl", "Julia", "Uiua", "Dave", 'signatures' );
+
+for my $example (@examples) {
+ my $output = reverse_vowels($example);
+
+ say <<~"END";
+ Input: \$s = "$example"
+ Output: "$output"
+ END
+}
+
+sub reverse_vowels ($string) {
+ my @vowels =
+ reverse
+ map { lc }
+ grep { /[aeiou]/mix }
+ split //, $string;
+ for my $i ( 0 .. -1 + length $string ) {
+ my $c = substr( $string, $i, 1 );
+ my $v = $c =~ /[aeiou]/mix ? 1 : 0;
+ if ( $c =~ /[aeiou]/mix ) {
+ my $n = shift @vowels;
+ $n = uc $n if $c eq uc $c;
+ substr( $string, $i, 1 ) = $n;
+ }
+ }
+
+ return $string;
+}