diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-31 13:20:59 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-31 13:20:59 +0000 |
| commit | efb201427ac08c6efb52258d2afb7adb3cc23fba (patch) | |
| tree | 24e0a625b8679ca980edd2fa43d8e228c76d97ed | |
| parent | c05e33d4361f0c9fbd112bea0bc69ea9e2e442f3 (diff) | |
| parent | 2a9e94d7b06c5b07b142183d0c0131372be5b1cb (diff) | |
| download | perlweeklychallenge-club-efb201427ac08c6efb52258d2afb7adb3cc23fba.tar.gz perlweeklychallenge-club-efb201427ac08c6efb52258d2afb7adb3cc23fba.tar.bz2 perlweeklychallenge-club-efb201427ac08c6efb52258d2afb7adb3cc23fba.zip | |
Merge pull request #9491 from jacoby/master
Blogged 254
| -rw-r--r-- | challenge-254/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-254/dave-jacoby/perl/ch-1.pl | 22 | ||||
| -rw-r--r-- | challenge-254/dave-jacoby/perl/ch-2.pl | 37 |
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; +} |
