aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-10-23 01:30:57 +0100
committerGitHub <noreply@github.com>2023-10-23 01:30:57 +0100
commitea797de68b4e00bdb2c1fe2b6a3503aa28f9e86f (patch)
tree86d3b17ed6a4df64d59557781db268258fd8eaec
parent8113c5a7283494eae37cea3ee07e001d1542d6f8 (diff)
parent45b3d932cfdbc7355f2144da6d4276272431491d (diff)
downloadperlweeklychallenge-club-ea797de68b4e00bdb2c1fe2b6a3503aa28f9e86f.tar.gz
perlweeklychallenge-club-ea797de68b4e00bdb2c1fe2b6a3503aa28f9e86f.tar.bz2
perlweeklychallenge-club-ea797de68b4e00bdb2c1fe2b6a3503aa28f9e86f.zip
Merge pull request #8921 from Util/c239
Add TWC 239 solutions by Bruce Gray (Raku only).
-rw-r--r--challenge-239/bruce-gray/raku/ch-1.raku19
-rw-r--r--challenge-239/bruce-gray/raku/ch-2.raku26
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-239/bruce-gray/raku/ch-1.raku b/challenge-239/bruce-gray/raku/ch-1.raku
new file mode 100644
index 0000000000..243f0d02a7
--- /dev/null
+++ b/challenge-239/bruce-gray/raku/ch-1.raku
@@ -0,0 +1,19 @@
+my &task1 = *.join eq *.join;
+
+
+# Alternate phrasings of the same solution:
+# my &task1 = { @^s1.join eq @^s2.join };
+# sub task1 ( @s1, @s2 --> Bool ) {
+# return @s1.join eq @s2.join;
+# }
+
+
+my @tests =
+ ( True , ( <ab c> , <a bc> ) ),
+ ( False , ( <ab c> , <ac b> ) ),
+ ( True , ( <ab cd e> , ('abcde',) ) ),
+;
+use Test; plan +@tests;
+for @tests -> ( Bool $expected, @in ) {
+ is task1(|@in), $expected;
+}
diff --git a/challenge-239/bruce-gray/raku/ch-2.raku b/challenge-239/bruce-gray/raku/ch-2.raku
new file mode 100644
index 0000000000..13bb6b0036
--- /dev/null
+++ b/challenge-239/bruce-gray/raku/ch-2.raku
@@ -0,0 +1,26 @@
+sub task2_via_Set ( Str $allowed, @s --> UInt ) {
+ my Set $a = $allowed.comb.Set;
+
+ return +grep { .comb.Set (-) $a ≡ ∅ }, @s;
+}
+
+sub task2_via_Regex ( Str $allowed, @s --> UInt ) {
+ return +grep / ^ @($allowed.comb.unique)+ $ /, @s;
+}
+
+
+my @tests =
+ ( 2, ( 'ab' , <ad bd aaab baa badab> ) ),
+ ( 7, ( 'abc' , <a b c ab ac bc abc> ) ),
+ ( 4, ( 'cad' , <cc acd b ba bac bad ac d> ) ),
+;
+my @subs =
+ :&task2_via_Set,
+ :&task2_via_Regex,
+;
+use Test; plan +@tests * +@subs;
+for @subs -> ( :key($sub_name), :value($task2) ) {
+ for @tests -> ( UInt $expected, @in ) {
+ is $task2.(|@in), $expected, "$sub_name @in[0]";
+ }
+} \ No newline at end of file