From b32f97d9402f129d263dce68d0ae4439d0466895 Mon Sep 17 00:00:00 2001 From: Asher Harvey-Smith Date: Sun, 6 Oct 2024 23:35:15 +0100 Subject: challenge 289 --- challenge-289/asherbhs/apl/ch-1.apl | 7 +++++++ challenge-289/asherbhs/raku/ch-1.raku | 8 ++++++++ challenge-289/asherbhs/raku/ch-2.raku | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 challenge-289/asherbhs/apl/ch-1.apl create mode 100644 challenge-289/asherbhs/raku/ch-1.raku create mode 100644 challenge-289/asherbhs/raku/ch-2.raku diff --git a/challenge-289/asherbhs/apl/ch-1.apl b/challenge-289/asherbhs/apl/ch-1.apl new file mode 100644 index 0000000000..110be4724d --- /dev/null +++ b/challenge-289/asherbhs/apl/ch-1.apl @@ -0,0 +1,7 @@ +⎕IO←0 + +ThirdMaximum←(⊢⌷⍨⍋⌷⍨≢-1+2×3≤≢)∪ + +⎕←ThirdMaximum 5 6 4 1 +⎕←ThirdMaximum 4 5 +⎕←ThirdMaximum 1 2 2 3 diff --git a/challenge-289/asherbhs/raku/ch-1.raku b/challenge-289/asherbhs/raku/ch-1.raku new file mode 100644 index 0000000000..acab2a1b92 --- /dev/null +++ b/challenge-289/asherbhs/raku/ch-1.raku @@ -0,0 +1,8 @@ +sub third-maximum(Int:D @ints where @ints ≥ 1 --> Int:D) { + @ints.unique.sort(&[Rcmp])[{$_ ≥ 3 ?? 2 !! 0}] + # [ * ≥ 3 ?? 2 !! 0 ] would be nice, but alas +} + +say third-maximum Array[Int](5, 6, 4, 1); +say third-maximum Array[Int](4, 5); +say third-maximum Array[Int](1, 2, 2, 3); diff --git a/challenge-289/asherbhs/raku/ch-2.raku b/challenge-289/asherbhs/raku/ch-2.raku new file mode 100644 index 0000000000..de0767c04b --- /dev/null +++ b/challenge-289/asherbhs/raku/ch-2.raku @@ -0,0 +1,21 @@ +sub jumbled-letters(Str:D $text --> Str:D) { + $text + .words + .map({ + my @chars = .subst(/\W/, :g).comb; + my @jumble = (@chars.head, |@chars[1 .. * - 2].pick(*), @chars.tail); + @jumble.splice: .from, 0, .Str for @$/; + @jumble.join + }) + .join(' ') +} + +say jumbled-letters 'Perl'; +say jumbled-letters "'Tisn't."; +say jumbled-letters q:to 'END'; + Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn’t mttaer in waht + oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist + and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you + can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed + ervey lteter by istlef, but the wrod as a wlohe. + END -- cgit