aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2024-10-04 11:52:03 +0100
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2024-10-04 11:52:03 +0100
commite19a3a6ba54a2b2236820f3cf878fe880e066777 (patch)
tree4112865f018169da32656a10b5b3de74f424a4c3
parent3f2b9ceb20236fba3255eab9d0b801799be564cc (diff)
downloadperlweeklychallenge-club-e19a3a6ba54a2b2236820f3cf878fe880e066777.tar.gz
perlweeklychallenge-club-e19a3a6ba54a2b2236820f3cf878fe880e066777.tar.bz2
perlweeklychallenge-club-e19a3a6ba54a2b2236820f3cf878fe880e066777.zip
- Updated solutions by Niels van Dijke.
-rwxr-xr-xchallenge-289/perlboy1967/perl/ch-1.pl13
-rwxr-xr-xchallenge-289/perlboy1967/perl/ch-2.pl5
2 files changed, 10 insertions, 8 deletions
diff --git a/challenge-289/perlboy1967/perl/ch-1.pl b/challenge-289/perlboy1967/perl/ch-1.pl
index a8d0fc1315..3b1f921715 100755
--- a/challenge-289/perlboy1967/perl/ch-1.pl
+++ b/challenge-289/perlboy1967/perl/ch-1.pl
@@ -20,17 +20,18 @@ use v5.32;
use feature qw(signatures);
no warnings qw(experimental::signatures);
use common::sense;
+use List::Util qw(uniq);
use Test2::V0 qw(-no_srand);
-sub nThMaximum :prototype(\@$) ($arInts,$n){
- my $n2 = ($#$arInts+1 >= $n ? $n : $#$arInts+1);
- (sort { $a <=> $b } @$arInts)[-$n2];
+sub nThMaximum :prototype(\@$) ($arInts,$n){
+ my @l = sort { $a <=> $b } uniq(@$arInts);
+ $l[@l < $n ? -1 : -$n];
}
is(nThMaximum(@{[5,6,4,1]},3),4,'Example 1');
-is(nThMaximum(@{[4,5]},3),4,'Example 2');
-is(nThMaximum(@{[1,2,2,3]},3),2,'Example 3');
-is(nThMaximum(@{[5,3,2]},2),3,'Own example');
+is(nThMaximum(@{[4,5]}, 3),5,'Example 2');
+is(nThMaximum(@{[1,2,2,3]},3),1,'Example 3');
+is(nThMaximum(@{[5,3,2]}, 2),3,'Own example');
done_testing;
diff --git a/challenge-289/perlboy1967/perl/ch-2.pl b/challenge-289/perlboy1967/perl/ch-2.pl
index 73a486a55e..4afd70bc2d 100755
--- a/challenge-289/perlboy1967/perl/ch-2.pl
+++ b/challenge-289/perlboy1967/perl/ch-2.pl
@@ -45,10 +45,11 @@ use common::sense;
use List::Util qw(shuffle);
sub jumbledLetters ($str) {
- $str =~ s{([a-z])([a-z]+)([a-z])}{$1.join('',shuffle split //,$2).$3}geisr;
+ $str =~ s{([A-Za-z])([A-Za-z]+)([A-Za-z])}
+ {$1.join('',shuffle split //,$2).$3}gesr;
}
-say jumbledLetters(<<EOT);
+say jumbledLetters(<<EOT);
According to a research at Cambridge University, it doesn't matter in what order
the letters in a word are, the only important thing is that the first and last
letter be at the right place. The rest can be a total mess and you can still