diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-30 22:01:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-30 22:01:02 +0100 |
| commit | 8c1a0beec1d0dac09dd376bedb36eb11cc56dfbb (patch) | |
| tree | 2b9c599e4f914fed25f54023e8a67e3994dedd83 | |
| parent | f0fa15d52d1d6e67e9cdc200876e7c6b0df836ad (diff) | |
| parent | ceb82af7db5446b9a6e85296d7abc8550924c7c9 (diff) | |
| download | perlweeklychallenge-club-8c1a0beec1d0dac09dd376bedb36eb11cc56dfbb.tar.gz perlweeklychallenge-club-8c1a0beec1d0dac09dd376bedb36eb11cc56dfbb.tar.bz2 perlweeklychallenge-club-8c1a0beec1d0dac09dd376bedb36eb11cc56dfbb.zip | |
Merge pull request #10937 from torgnylyon/master
Add solutions for week 289
| -rw-r--r-- | challenge-289/torgny-lyon/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-289/torgny-lyon/perl/ch-1.pl | 16 | ||||
| -rwxr-xr-x | challenge-289/torgny-lyon/perl/ch-2.pl | 16 |
3 files changed, 33 insertions, 0 deletions
diff --git a/challenge-289/torgny-lyon/blog.txt b/challenge-289/torgny-lyon/blog.txt new file mode 100644 index 0000000000..dfa8f90929 --- /dev/null +++ b/challenge-289/torgny-lyon/blog.txt @@ -0,0 +1 @@ +https://www.abc.se/~torgny/pwc.html#289 diff --git a/challenge-289/torgny-lyon/perl/ch-1.pl b/challenge-289/torgny-lyon/perl/ch-1.pl new file mode 100755 index 0000000000..8b36455377 --- /dev/null +++ b/challenge-289/torgny-lyon/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use v5.40; + +use Test::More tests => 3; + +use List::Util qw(uniq); + +sub get_third_maximum { + my @l = uniq sort { $b <=> $a } @_; + return @l > 2 ? $l[2] : $l[0]; +} + +is(get_third_maximum(5, 6, 4, 1), 4); +is(get_third_maximum(4, 5), 5); +is(get_third_maximum(1, 2, 2, 3), 1); diff --git a/challenge-289/torgny-lyon/perl/ch-2.pl b/challenge-289/torgny-lyon/perl/ch-2.pl new file mode 100755 index 0000000000..633e165850 --- /dev/null +++ b/challenge-289/torgny-lyon/perl/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use v5.40; + +use List::Util qw(shuffle); + +my $s = <<END; +This supposed Cambridge research is unfortunately an urban legend. However, +the effect has been studied. For example—and with a title that probably +made the journal’s editor a little nervous—Raeding wrods with jubmled +lettres: there is a cost by Rayner, White, et. al. looked at reading speed +and comprehension of jumbled text. +END + +say $s; +say $s =~ s/(\pL)(\pL{2,})(\pL)/$1 . (join '', shuffle(split q(), $2)) . $3/reg; |
