diff options
| author | Mark Anderson <mark@andemark.io> | 2024-10-01 17:22:05 +0000 |
|---|---|---|
| committer | Mark Anderson <mark@andemark.io> | 2024-10-01 17:22:05 +0000 |
| commit | 71e73f8770244bb51b12c37cfb43aff1eca5e7e6 (patch) | |
| tree | b395d25656aab6cb46d440675836a99a6e2add04 | |
| parent | 3260fe0e07221d6637b73740228a1b29678cea51 (diff) | |
| download | perlweeklychallenge-club-71e73f8770244bb51b12c37cfb43aff1eca5e7e6.tar.gz perlweeklychallenge-club-71e73f8770244bb51b12c37cfb43aff1eca5e7e6.tar.bz2 perlweeklychallenge-club-71e73f8770244bb51b12c37cfb43aff1eca5e7e6.zip | |
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 | 27 |
2 files changed, 38 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..730816d540 --- /dev/null +++ b/challenge-289/mark-anderson/raku/ch-2.raku @@ -0,0 +1,27 @@ +#!/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); + +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 +} |
