diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-10-02 21:09:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-02 21:09:46 +0100 |
| commit | eaefd6a35935cf175ba3e13fb6687367881cd1c9 (patch) | |
| tree | f97b36a602099d466d7f4b812c637958946740f4 | |
| parent | 3260fe0e07221d6637b73740228a1b29678cea51 (diff) | |
| parent | 367203c52b72a1ea83ff578f890cdcb99ad41bf5 (diff) | |
| download | perlweeklychallenge-club-eaefd6a35935cf175ba3e13fb6687367881cd1c9.tar.gz perlweeklychallenge-club-eaefd6a35935cf175ba3e13fb6687367881cd1c9.tar.bz2 perlweeklychallenge-club-eaefd6a35935cf175ba3e13fb6687367881cd1c9.zip | |
Merge pull request #10942 from andemark/challenge-289
Challenge 289 Solutions (Raku)
| -rw-r--r-- | challenge-289/mark-anderson/raku/ch-1.raku | 11 | ||||
| -rw-r--r-- | challenge-289/mark-anderson/raku/ch-2.raku | 29 |
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-289/mark-anderson/raku/ch-1.raku b/challenge-289/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..4c84b1277d --- /dev/null +++ b/challenge-289/mark-anderson/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku +use Test; + +is third-max(5,6,4,1), 4; +is third-max(4,5), 5; +is third-max(1,2,2,3), 1; + +sub third-max(+@ints) +{ + .[2] // .[0] given @ints.unique.sort(-*) +} diff --git a/challenge-289/mark-anderson/raku/ch-2.raku b/challenge-289/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..51d689e0a5 --- /dev/null +++ b/challenge-289/mark-anderson/raku/ch-2.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +my $text = chomp q:to/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 jumbled-letters($text); + +say jumbled-letters("They've shouldn't've, __LINE__ under_score y'all you're"); + +sub jumbled-letters($text) +{ + my @split = $text.split(/ <[\s — -]> /, :v); + + for @split[0,2...*] + { + my @chars = .comb; + my @alphas = @chars.grep(* (elem) ['a'...'z','A'...'Z'], :k); + @chars[@alphas[1..*-2]] .= pick(*); + $_ = [~] @chars + } + + [~] @split +} |
