aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrir <rirans@comcast.net>2024-06-14 23:29:42 -0400
committerrir <rirans@comcast.net>2024-06-14 23:29:42 -0400
commit1c938200c9e497031bfc4dd3dcad0775412638c1 (patch)
tree98bd55b062453ae2b71a156486940573326a9328
parent194611acf9d0f7f165ac0ec595774b2c6fd5f413 (diff)
downloadperlweeklychallenge-club-1c938200c9e497031bfc4dd3dcad0775412638c1.tar.gz
perlweeklychallenge-club-1c938200c9e497031bfc4dd3dcad0775412638c1.tar.bz2
perlweeklychallenge-club-1c938200c9e497031bfc4dd3dcad0775412638c1.zip
273
-rw-r--r--challenge-273/0rir/raku/ch-1.raku55
-rw-r--r--challenge-273/0rir/raku/ch-2.raku53
2 files changed, 108 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..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;
+
+