aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-289/mark-anderson/raku/ch-1.raku11
-rw-r--r--challenge-289/mark-anderson/raku/ch-2.raku29
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
+}