aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-282/0rir/raku/ch-1.raku72
-rw-r--r--challenge-282/0rir/raku/ch-2.raku56
2 files changed, 128 insertions, 0 deletions
diff --git a/challenge-282/0rir/raku/ch-1.raku b/challenge-282/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..d654875fe4
--- /dev/null
+++ b/challenge-282/0rir/raku/ch-1.raku
@@ -0,0 +1,72 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # πŸ¦‹ βˆ…βˆͺβˆ©βˆ‹βˆˆβˆ‰βŠ† ≑ β‰’ «␀ Β» ∴
+use v6.d;
+use Test;
+
+=begin comment
+282-1: Good Integer Submitted by: Mohammad Sajid Anwar
+
+You are given a positive integer, $int, having 3 or more digits.
+Write a script to return the Good Integer in the given integer or -1 if
+none found.
+
+A good integer is exactly three consecutive matching digits.
+
+Example 1
+Input: $int = 12344456
+Output: "444"
+Example 2
+Input: $int = 1233334
+Output: -1
+Example 3
+Input: $int = 10020003
+Output: "000"
+=end comment
+
+no worries;
+ my @Test =
+ 000, -1,
+ 100, -1,
+ 123, -1,
+ 111, "111",
+ 1111, -1,
+ 1121, -1,
+ 1112, "111",
+ 00011, -1,
+ 21112, "111",
+ 211112, -1,
+ 000111, "111",
+ 111000, "111",
+ 111222, "111",
+ 1111000, "000",
+ 1110000, "111",
+ 1111222, "222",
+ 1234111, "111",
+ 1233334, -1,
+ 1234445, "444",
+ 10020003, "000",
+ 12344456, "444",
+ ('1234567890' x 100).Int, -1,
+ ('11' ~ ('1234567890' x 100)).Int, '111',
+ (('1234567890' x 100) ~ '00').Int, '000',
+;
+
+use worries;
+plan @Test Γ· 2;
+
+sub task( UInt $a -->Any) {
+
+ if $a ~~ m:g/ ([$<w> = \d] $<w>**2..* ) / {
+ return $/.list.first( *.chars == 3) // -1;
+ }
+ -1;
+}
+
+for @Test -> $in, $exp {
+ is task($in), $exp, "$exp <- $in";
+}
+
+done-testing;
+my $int = 999999999888888887777777666666555554444333221000;
+say "\nInput: \$int = $int\nOutput: { task $int }\n";
+
diff --git a/challenge-282/0rir/raku/ch-2.raku b/challenge-282/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..ef8e449a53
--- /dev/null
+++ b/challenge-282/0rir/raku/ch-2.raku
@@ -0,0 +1,56 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # πŸ¦‹ βˆ…βˆͺβˆ©βˆ‹βˆˆβˆ‰βŠ† ≑ β‰’ «␀ Β» ∴
+use v6.d;
+use Test;
+
+=begin comment
+282-2: Changing Keys Submitted by: Mohammad Sajid Anwar
+
+You are given an alphabetic string, $str, as typed by user.
+Write a script to find the number of times user had to change the key to
+type the given string. Changing key is defined as using a key different
+from the last used key. The shift and caps lock keys won’t be counted.
+
+Example 1
+Input: $str = 'pPeERrLl'
+Ouput: 3
+
+p -> P : 0 key change
+P -> e : 1 key change
+e -> E : 0 key change
+E -> R : 1 key change
+R -> r : 0 key change
+r -> L : 1 key change
+L -> l : 0 key change
+
+Example 2
+Input: $str = 'rRr'
+Ouput: 0
+Example 3
+Input: $str = 'GoO'
+Ouput: 1
+=end comment
+
+my @Test =
+ '', 0,
+ 'a', 0,
+ 'aA', 0,
+ 'pPeERrLl', 3,
+ 'rRr', 0,
+ 'GoO', 1,
+;
+plan @Test Γ· 2;
+
+multi task( '' ) { 0 }
+multi task( Str:D $a) {
+ +$a.lc.comb.squish -1;
+}
+
+for @Test -> $in, $exp {
+ is task($in), $exp, "$exp <- $in";
+}
+done-testing;
+
+my $str = 'pPjtrliuhjtlijhaWRtaaeERrLl';
+say "\nInput: \$str = '$str'\nOutput: { task $str }\n";
+