aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-289/dave-jacoby/blog.txt1
-rw-r--r--challenge-289/dave-jacoby/perl/ch-1.pl31
-rw-r--r--challenge-289/dave-jacoby/perl/ch-2.pl40
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;
+}