diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2024-10-01 16:21:37 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2024-10-01 16:21:37 -0400 |
| commit | f3941f09b5ed2cbc2da0eef3ea57863eac2c5839 (patch) | |
| tree | 1a58e6b5806242966d0f8b1c18245ef58e491b0a | |
| parent | 3260fe0e07221d6637b73740228a1b29678cea51 (diff) | |
| download | perlweeklychallenge-club-f3941f09b5ed2cbc2da0eef3ea57863eac2c5839.tar.gz perlweeklychallenge-club-f3941f09b5ed2cbc2da0eef3ea57863eac2c5839.tar.bz2 perlweeklychallenge-club-f3941f09b5ed2cbc2da0eef3ea57863eac2c5839.zip | |
DAJ 289
| -rw-r--r-- | challenge-289/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-289/dave-jacoby/perl/ch-1.pl | 31 | ||||
| -rw-r--r-- | challenge-289/dave-jacoby/perl/ch-2.pl | 40 |
3 files changed, 72 insertions, 0 deletions
diff --git a/challenge-289/dave-jacoby/blog.txt b/challenge-289/dave-jacoby/blog.txt new file mode 100644 index 0000000000..72e5b2400b --- /dev/null +++ b/challenge-289/dave-jacoby/blog.txt @@ -0,0 +1 @@ +https://jacoby-lpwk.onrender.com/2024/10/01/irregular-use-of-regular-expressions-weekly-challenge-289.html diff --git a/challenge-289/dave-jacoby/perl/ch-1.pl b/challenge-289/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..2220b86022 --- /dev/null +++ b/challenge-289/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say state postderef signatures }; + +use List::Util qw{ uniq }; + +my @examples = ( + + [ 5, 6, 4, 1 ], + [ 4, 5 ], + [ 1, 2, 2, 3 ], + +); + +for my $example (@examples) { + my $output = third_maximum( $example->@* ); + my $input = join ', ', $example->@*; + say <<"END"; + Input: \$ints = ($input) + Output: $output +END +} + +sub third_maximum (@array) { + my @new = reverse uniq sort @array; + return $new[2] if defined $new[2]; + return shift @new; +} + diff --git a/challenge-289/dave-jacoby/perl/ch-2.pl b/challenge-289/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..a0cf0f97ed --- /dev/null +++ b/challenge-289/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say state postderef signatures }; + +use List::Util qw{ min max }; + +my @examples = ( + + 'Perl is different. In a nutshell, Perl is designed to make +the easy jobs easy, without making the hard jobs impossible.', + + 'According to Larry Wall(1), the original author of the Perl +programming language, there are three great virtues of a +programmer; Laziness, Impatience and Hubris.', + + q{If you haven't used regular expressions before, a tutorial +introduction is available in perlretut. If you know just a +little about them, a quick-start introduction is available +in perlrequick.}, + + 'THIS looks like a job for RECURSION!', +); + +for my $input (@examples) { + my $output = $input; + $output =~ s{(\w)(\w+)(\w)}{ $1 . jumble_letters( $2 ) . $3 }gmxe; + + say $input; + say '-----'; + say $output; + say ''; +} + +sub jumble_letters ($str) { + $str = join '', sort { rand 10 <=> rand 10 } + split //, $str; + return $str; +} |
