From 1c938200c9e497031bfc4dd3dcad0775412638c1 Mon Sep 17 00:00:00 2001 From: rir Date: Fri, 14 Jun 2024 23:29:42 -0400 Subject: 273 --- challenge-273/0rir/raku/ch-1.raku | 55 +++++++++++++++++++++++++++++++++++++++ challenge-273/0rir/raku/ch-2.raku | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 challenge-273/0rir/raku/ch-1.raku create mode 100644 challenge-273/0rir/raku/ch-2.raku diff --git a/challenge-273/0rir/raku/ch-1.raku b/challenge-273/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..ae6e95a181 --- /dev/null +++ b/challenge-273/0rir/raku/ch-1.raku @@ -0,0 +1,55 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ +use v6.d; +INIT $*RAT-OVERFLOW = FatRat; +use lib $?FILE.IO.cleanup.parent(2).add("lib"); +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, +; +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; + + -- cgit From b2da84baa5ded4451f460c4e28fd81d4105389c5 Mon Sep 17 00:00:00 2001 From: rir Date: Fri, 14 Jun 2024 23:45:55 -0400 Subject: de-cruft --- challenge-273/0rir/raku/ch-1.raku | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/challenge-273/0rir/raku/ch-1.raku b/challenge-273/0rir/raku/ch-1.raku index ae6e95a181..0465e7f56c 100644 --- a/challenge-273/0rir/raku/ch-1.raku +++ b/challenge-273/0rir/raku/ch-1.raku @@ -1,8 +1,6 @@ #!/usr/bin/env raku # :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ use v6.d; -INIT $*RAT-OVERFLOW = FatRat; -use lib $?FILE.IO.cleanup.parent(2).add("lib"); use Test; =begin comment @@ -33,13 +31,19 @@ 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, + "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; -- cgit