aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetilS <kjetilskotheim@gmail.com>2024-10-01 03:41:08 +0200
committerKjetilS <kjetilskotheim@gmail.com>2024-10-01 03:41:08 +0200
commitf23f44dd98e4ca2e2ff95561dee7836e4f5960ae (patch)
tree9d845fa7c804d5ac3dbee98812f6ee444d4209e7
parent3114956979e812e8ca166cb84d8dea346cee22d3 (diff)
downloadperlweeklychallenge-club-f23f44dd98e4ca2e2ff95561dee7836e4f5960ae.tar.gz
perlweeklychallenge-club-f23f44dd98e4ca2e2ff95561dee7836e4f5960ae.tar.bz2
perlweeklychallenge-club-f23f44dd98e4ca2e2ff95561dee7836e4f5960ae.zip
https://theweeklychallenge.org/blog/perl-weekly-challenge-289/
-rw-r--r--challenge-289/kjetillll/perl/ch-1.pl12
-rw-r--r--challenge-289/kjetillll/perl/ch-2.pl26
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-289/kjetillll/perl/ch-1.pl b/challenge-289/kjetillll/perl/ch-1.pl
new file mode 100644
index 0000000000..476c6df349
--- /dev/null
+++ b/challenge-289/kjetillll/perl/ch-1.pl
@@ -0,0 +1,12 @@
+use strict; use warnings; use v5.10; use List::Util 'uniq'; use Test::More;
+
+sub third_max {
+ my( $third_max, $max ) = ( uniq sort { $b <=> $a } @_ )[ 2, 0 ];
+ $third_max // $max
+}
+
+say third_max(@ARGV) and exit if @ARGV;
+is third_max(5, 6, 4, 1) => 4;
+is third_max(4, 5) => 5;
+is third_max(1, 2, 2, 3) => 1;
+done_testing;
diff --git a/challenge-289/kjetillll/perl/ch-2.pl b/challenge-289/kjetillll/perl/ch-2.pl
new file mode 100644
index 0000000000..f9ab1bf498
--- /dev/null
+++ b/challenge-289/kjetillll/perl/ch-2.pl
@@ -0,0 +1,26 @@
+use strict; use warnings; use List::Util 'shuffle'; use v5.26;
+
+sub jumbled_letters {
+ pop =~ s{
+ \b #border between a \w and a non-\w
+ ([a-z]) #first letter in a word, upper or lower case due to /i
+ ([a-z]+) #middle part of a word, at least one letter
+ ([a-z]) #last letter
+ \b
+ }{
+ $1
+ . join('', shuffle split'', $2)
+ . $3
+ }geirx
+}
+
+my $text = @ARGV ? "@ARGV" : <<~'🛑';
+ Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn’t
+ mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt
+ tihng is taht the frist and lsat ltteer be at the rghit pclae. The
+ rset can be a toatl mses and you can sitll raed it wouthit
+ porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter
+ by istlef, but the wrod as a wlohe.
+ 🛑
+
+print jumbled_letters($text);