diff options
| -rw-r--r-- | challenge-289/kjetillll/perl/ch-1.pl | 12 | ||||
| -rw-r--r-- | challenge-289/kjetillll/perl/ch-2.pl | 26 |
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); |
