From 2a9e94d7b06c5b07b142183d0c0131372be5b1cb Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Mon, 29 Jan 2024 17:28:30 -0500 Subject: Blogged 254 --- challenge-254/dave-jacoby/blog.txt | 1 + challenge-254/dave-jacoby/perl/ch-1.pl | 22 ++++++++++++++++++++ challenge-254/dave-jacoby/perl/ch-2.pl | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 challenge-254/dave-jacoby/blog.txt create mode 100644 challenge-254/dave-jacoby/perl/ch-1.pl create mode 100644 challenge-254/dave-jacoby/perl/ch-2.pl 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; +} -- cgit