diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-15 15:00:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-15 15:00:59 +0100 |
| commit | e4dd309f44995febd08b18adefdf87dfbeded637 (patch) | |
| tree | f29b4669371d9a862e8431c317ec5af8803b5606 | |
| parent | 194611acf9d0f7f165ac0ec595774b2c6fd5f413 (diff) | |
| parent | b2da84baa5ded4451f460c4e28fd81d4105389c5 (diff) | |
| download | perlweeklychallenge-club-e4dd309f44995febd08b18adefdf87dfbeded637.tar.gz perlweeklychallenge-club-e4dd309f44995febd08b18adefdf87dfbeded637.tar.bz2 perlweeklychallenge-club-e4dd309f44995febd08b18adefdf87dfbeded637.zip | |
Merge pull request #10262 from 0rir/work
273
| -rw-r--r-- | challenge-273/0rir/raku/ch-1.raku | 59 | ||||
| -rw-r--r-- | challenge-273/0rir/raku/ch-2.raku | 53 |
2 files changed, 112 insertions, 0 deletions
diff --git a/challenge-273/0rir/raku/ch-1.raku b/challenge-273/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..0465e7f56c --- /dev/null +++ b/challenge-273/0rir/raku/ch-1.raku @@ -0,0 +1,59 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +Task 1: Percentage of Character +Submitted by: Mohammad Sajid Anwar +You are given a string, $str and a character $char. + +Write a script to return the percentage, nearest whole, of given character in the given string. + +Example 1 +Input: $str = "perl", $char = "e" +Output: 25 +Example 2 +Input: $str = "java", $char = "a" +Output: 50 +Example 3 +Input: $str = "python", $char = "m" +Output: 0 +Example 4 +Input: $str = "ada", $char = "a" +Output: 67 +Example 5 +Input: $str = "ballerina", $char = "l" +Output: 22 +Example 6 +Input: $str = "analitik", $char = "k" +Output: 13 +=end comment + +my @Test = + "perl", "e", 25, + "java", "a", 50, + "python", "m", 0, + "ada", "a", 67, + "ballerina", "l", 22, + "analitik", "k", 13, + 'a', "a", 100, + 'a' x 100 ~ 'b', 'a', 99, + 'a' x 100 ~ 'b', 'b', 1, + 'a' x 200 ~ 'b', 'a', 100, + 'a' x 200 ~ 'b', 'b', 0, + 'a' x 199 ~ 'b', 'a', 100, + 'a' x 199 ~ 'b', 'b', 1, +; +plan @Test ÷ 3; + +sub task( $word, $letter) { + my @w = $word.comb; + (100 × @w.grep( $letter) ÷ @w).round; +} + +for @Test -> $in, $letter, $exp { + is task($in, $letter), $exp, "$exp <- ($letter) $in"; +} + +done-testing; diff --git a/challenge-273/0rir/raku/ch-2.raku b/challenge-273/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..267e402c7f --- /dev/null +++ b/challenge-273/0rir/raku/ch-2.raku @@ -0,0 +1,53 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +273-2: B After A Submitted by: Mohammad Sajid Anwar +You are given a string, $str. + +Write a script to return true if there is at least one b, and no a appears after the first b. + +Example 1 +Input: $str = "aabb" +Output: true +Example 2 +Input: $str = "abab" +Output: false +Example 3 +Input: $str = "aaa" +Output: false +Example 4 +Input: $str = "bbb" +Output: true + +=end comment + +my @Test = + "aabb", True, + "abab", False, + "aaa", False, + "bbb", True, + "ccc", False, + "cbc", True, + "cac", False, + "cab", True, +; +plan @Test ÷ 2; + +sub task( $word) { + my @w = $word.comb; + without my $b-k = @w.first( 'b', :k) { return False } + with + @w[++$b-k..^@w].first( 'a') { return False } + True; +} + +for @Test -> $in, $exp { + is task($in), $exp, "$exp\t<- $in"; +} + +done-testing; + + |
