diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-11 12:50:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-11 12:50:28 +0100 |
| commit | d13c7851bebe9bf4315ed4e8787cbeacf80c215b (patch) | |
| tree | dfab80a01316eec402e4eeb14ba6ad2da4903f1e | |
| parent | 514530d6be7cc5067a95a11ebedff9e0d4d46cfe (diff) | |
| parent | 75aa0f2a5cc9e834db897e64e97ab7a0fb2d4943 (diff) | |
| download | perlweeklychallenge-club-d13c7851bebe9bf4315ed4e8787cbeacf80c215b.tar.gz perlweeklychallenge-club-d13c7851bebe9bf4315ed4e8787cbeacf80c215b.tar.bz2 perlweeklychallenge-club-d13c7851bebe9bf4315ed4e8787cbeacf80c215b.zip | |
Merge pull request #10238 from andemark/challenge-273
Challenge 273 Solutions (Raku)
| -rw-r--r-- | challenge-273/mark-anderson/raku/ch-1.raku | 14 | ||||
| -rw-r--r-- | challenge-273/mark-anderson/raku/ch-2.raku | 54 |
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-273/mark-anderson/raku/ch-1.raku b/challenge-273/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..33af93d32c --- /dev/null +++ b/challenge-273/mark-anderson/raku/ch-1.raku @@ -0,0 +1,14 @@ +#!/usr/bin/env raku +use Test; + +is perc-of-char('perl', 'e'), 25; +is perc-of-char('java', 'a'), 50; +is perc-of-char('python', 'm'), 0; +is perc-of-char('ada', 'a'), 67; +is perc-of-char('ballerina', 'l'), 22; +is perc-of-char('analitik', 'k'), 13; + +sub perc-of-char($str, $char) +{ + round 100 * $str.indices($char) / $str.chars +} diff --git a/challenge-273/mark-anderson/raku/ch-2.raku b/challenge-273/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..d769f0bb69 --- /dev/null +++ b/challenge-273/mark-anderson/raku/ch-2.raku @@ -0,0 +1,54 @@ +#!/usr/bin/env raku +use Test; + +ok b-after-a("aabb"); +nok b-after-a("abab"); +nok b-after-a("aaa"); +ok b-after-a("bbb"); +ok b-after-a("aaabxyzbcde"); +nok b-after-a("aaabxayzbcde"); +nok b-after-a("aaabxyzbcade"); +nok b-after-a("aaabxyzcde"); + +ok b-after-a-pos("aabb"); +nok b-after-a-pos("abab"); +nok b-after-a-pos("aaa"); +ok b-after-a-pos("bbb"); +ok b-after-a-pos("aaabxyzbcde"); +nok b-after-a-pos("aaabxayzbcde"); +nok b-after-a-pos("aaabxyzbcade"); +nok b-after-a-pos("aaabxyzcde"); + +ok b-after-a-indices("aabb"); +nok b-after-a-indices("abab"); +nok b-after-a-indices("aaa"); +ok b-after-a-indices("bbb"); +ok b-after-a-indices("aaabxyzbcde"); +nok b-after-a-indices("aaabxayzbcde"); +nok b-after-a-indices("aaabxyzbcade"); +nok b-after-a-indices("aaabxyzcde"); + +# Note: I may have misunderstood the problem. I thought it was to check +# for a 'b' and then a 'b' after the first 'b' and no 'a' after the first +# 'b' but it looks like others have checked for a 'b' and no 'a' after +# that first 'b' 🤷 + +sub b-after-a($str) +{ + $str ~~ / ^ <-[b]>* b <-[a]>* b <-[a]>* $ / +} + +sub b-after-a-pos($str) +{ + my $b = $str ~~ m:1st / b / || return False; + my $a-after-b = $str ~~ m:c($b.pos):1st/ a /; + my $b-after-b = $str ~~ m:c($b.pos):1st/ b /; + $b-after-b and not $a-after-b +} + +sub b-after-a-indices($str) +{ + my @a = $str.indices('a'); + my @b = $str.indices('b'); + @b > 1 and all(@a) < @b.head +} |
