aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-316/0rir/raku/ch-1.raku50
-rw-r--r--challenge-316/0rir/raku/ch-2.raku68
-rw-r--r--challenge-317/0rir/raku/ch-1.raku71
-rw-r--r--challenge-317/0rir/raku/ch-2.raku64
4 files changed, 253 insertions, 0 deletions
diff --git a/challenge-316/0rir/raku/ch-1.raku b/challenge-316/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..9c3e21c98b
--- /dev/null
+++ b/challenge-316/0rir/raku/ch-1.raku
@@ -0,0 +1,50 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # πŸ¦‹ βˆ…βˆͺβˆ©βˆ‹βˆˆβˆ‰βŠ† ≑ β‰’ «␀ Β» ∴
+use v6.d;
+use Test;
+
+=begin comment
+316-1 Circular Submitted by: Mohammad Sajid Anwar
+You are given a list of words.
+Write a script to find out whether the last character of each word is the first character of the following word.
+
+Example 1
+Input: @list = ("perl", "loves", "scala")
+Output: true
+
+Example 2
+Input: @list = ("love", "the", "programming")
+Output: false
+
+Example 3
+Input: @list = ("java", "awk", "kotlin", "node.js")
+Output: true
+
+=end comment
+
+my @Test =
+ ("java", "awk", "kotlin", "node.js"), True,
+ ("love", "the", "programming"), False,
+ ("perl", "loves", "scala"), True,
+ ('a',), Bool,
+ (), Bool,
+;
+plan @Test Γ· 2;
+
+multi task( @a where *.elems < 2 -->Bool ) { Bool }
+multi task( @a -->Bool ) {
+ for @a.rotor( 2 => -1) ->@d {
+ return False if @d[0].substr( *-1,1) ne @d[1].substr( 0,1);
+ }
+ True;
+}
+
+for @Test -> $in, $exp {
+ is task( $in), $exp, "{$exp // $exp.^name()} <- $in.raku()";
+}
+done-testing;
+
+my @list = ("java", "awk", "kotlin", "node.js");
+say qq{\nInput: @list = ("@list.join( '", "')")}
+ ~ "\nOutput: &task( @list)";
+
diff --git a/challenge-316/0rir/raku/ch-2.raku b/challenge-316/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..ab626e63ff
--- /dev/null
+++ b/challenge-316/0rir/raku/ch-2.raku
@@ -0,0 +1,68 @@
+#!/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
+316-2: Subsequence Submitted by: Mohammad Sajid Anwar
+
+You are given two string.
+Write a script to find out if one string is a subsequence of another.
+A subsequence of a string is a new string that is formed from the original string
+by deleting some (can be none) of the characters without disturbing the relative
+positions of the remaining characters.
+
+Example 1
+Input: $str1 = "uvw", $str2 = "bcudvew"
+Output: true
+
+Example 2
+Input: $str1 = "aec", $str2 = "abcde"
+Output: false
+
+Example 3
+Input: $str1 = "sip", $str2 = "javascript"
+Output: true
+
+=end comment
+
+my @Test =
+ "uvw", "bcudvew", True,
+ "aec", "abcde", False,
+ "sip", "javascript", True,
+ 'uvw', 'uvw', True,
+ 'a', 'a', True,
+ 'aaa', 'aaaa', True,
+ 'a', 'b', False,
+ 'aa', 'a', False,
+ '', 'a', Bool,
+ 'a', '', Bool,
+ Any, 'a', Bool,
+ 'a', Any, Bool,
+ Any, Any, Bool,
+;
+
+plan @Test Γ· 3;
+
+multi task( Any:U $subq, Any:D $str) { Bool }
+multi task( $subq, Any:U $str) { Bool }
+multi task( '', $str ) { Bool }
+multi task( $subq, '' ) { Bool }
+#multi task( Any:D $subq, Any:D $str where *.chars < $subq.chars) { False }
+multi task( Any:D $subq, Any:D $str -->Bool) {
+ so $str ~~ EVAL '/' ~ $subq.comb.join( ' .*? ' ) ~ '/';
+}
+
+for @Test -> $sub, $str, $exp {
+ is task( $sub, $str), $exp,
+ "{$exp // $exp.^name()} <- $sub.raku() ∘∘ $str.raku()";
+}
+done-testing;
+
+my $s1 = "avast";
+my $s2 = "javascript";
+say qq{\nInput: \$str1 = "$s1", \$str2 = "$s2"\nOutput: &task($s1, $s2)};
+
+
diff --git a/challenge-317/0rir/raku/ch-1.raku b/challenge-317/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..7182188c91
--- /dev/null
+++ b/challenge-317/0rir/raku/ch-1.raku
@@ -0,0 +1,71 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # πŸ¦‹ βˆ…βˆͺβˆ©βˆ‹βˆˆβˆ‰βŠ† ≑ β‰’ «␀ Β» ∴
+use v6.d;
+use Test;
+
+=begin comment
+317-1: Acronyms Submitted by: Mohammad Sajid Anwar
+You are given an array of words and a word.
+Write a script to return true if concatenating the first letter of each word in the given array matches the given word, return false otherwise.
+
+Example 1
+Input: @array = ("Perl", "Weekly", "Challenge")
+ $word = "PWC"
+Output: true
+
+Example 2
+Input: @array = ("Bob", "Charlie", "Joe")
+ $word = "BCJ"
+Output: true
+
+Example 3
+Input: @array = ("Morning", "Good")
+ $word = "MM"
+Output: false
+=end comment
+
+my @Test =
+ # word list word expect
+ ["Perl", "Weekly", "Challenge"], "PWC", True,
+ ["Bob", "Charlie", "Joe"], "BCJ", True,
+ ["bob", "charlie", "Joey"], "BCJ", True,
+ ["Morning", "Good"], "MM", False,
+;
+my @Dead =
+ ("",), Str,
+ (), "",
+ ("",), "",
+ ("Abc"), "",
+ ("Abc", "", "Bcd"), "AB",
+ ("bob", "", "Joey"), "BCJ",
+ ("",), "A",
+ Array, "A",
+;
+plan (@Test Γ· 3 + @Dead Γ· 2);
+
+multi task( Str:U, @list ) { die 'Word arg undefined.'}
+multi task( Str:D $word where * eq '', @list) { die 'Word arg empty.'}
+multi task( Str:D $word, Array:U ) { die 'List arg undefined.'}
+multi task( Str:D $word, Empty ) { die 'List arg Empty.'}
+multi task( Str:D $word, @list where *.first('').defined )
+ { die 'List contains "".'}
+multi task( Str:D $word, @list -->Bool) {
+ return False if @list.elems β‰  $word.chars;
+ so $word.fc eq all @listΒ».substr(0,1).join.fc;
+}
+
+for @Test -> @wordlist, $word, $exp {
+ is task( $word, @wordlist), $exp, "$exp <- @wordlist.raku() ∘∘ $word";
+}
+for @Dead -> $wordlist, $word {
+ dies-ok { task $word, $wordlist},
+ "Undef, Empty, or missmatch: @$wordlist.raku() ∘∘ $word.raku()";
+}
+done-testing;
+
+my @array = < Perl Weekly Challenge challenging weekly for 317 weeks>;
+my $word = "PWCCWF3W";
+say qq{\nInput: @array = ("} ~ @array.join('", "') ~ ")\n"
+ ~ "\$word = $word\n"
+ ~ "Output: { task $word, @array}";
+
diff --git a/challenge-317/0rir/raku/ch-2.raku b/challenge-317/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..b5b587fc4c
--- /dev/null
+++ b/challenge-317/0rir/raku/ch-2.raku
@@ -0,0 +1,64 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # πŸ¦‹ βˆ…βˆͺβˆ©βˆ‹βˆˆβˆ‰βŠ† ≑ β‰’ «␀ Β» ∴
+use v6.d;
+use Test;
+
+=begin comment
+317-2: Friendly Strings Submitted by: Mohammad Sajid Anwar
+You are given two strings.
+Write a script to return true if swapping any two letters in one string
+match the other string, return false otherwise.
+
+Example 1
+Input: $str1 = "desc", $str2 = "dsec"
+Output: true
+
+Example 2
+Input: $str1 = "fuck", $str2 = "fcuk"
+Output: true
+
+Example 3
+Input: $str1 = "poo", $str2 = "eop"
+Output: false
+
+Example 4
+Input: $str1 = "stripe", $str2 = "sprite"
+Output: true
+
+=end comment
+
+my @Test =
+ # $a, $b $exp
+ "desc", "dsec", True,
+ "luck", "lcuk", True,
+ "poo", "eop", False,
+ "stripe", "sprite", True,
+ "", "", False,
+ "ab", "a", False,
+ "ab", "ab", False,
+ "ba", "ab", True,
+ "abc", "abc", False,
+ "abc", "cab", False,
+ "abcd", "abcde", False,
+;
+plan @Test Γ· 3;
+
+constant \Switch-ct = 2;
+
+multi task( Str:D $a where *.chars < Switch-ct, Str:D $b -->False) {}
+multi task( Str:D $a, Str:D $b where *.chars ne $a.chars -->False) {}
+multi task( Str:D $a, Str:D $b --> Bool) {
+ return False unless $a.comb.sort ~~ $b.comb.sort;
+ Switch-ct == ( [Z,] $a.comb, $b.comb).grep: { .[0] ne .[1]};
+}
+
+for @Test -> $a, $b, $exp {
+ is task( $a, $b), $exp, "{$exp // $exp.^name()} <- $a ∘∘ $b";
+}
+done-testing;
+
+my $str1 = "desc";
+my $str2 = "dsec";
+say qq{\nInput: \$str1 = "$str1", \$str2 = "$str2"\n}
+ ~ "Output: {task $str1, $str2 }";
+