aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-253/massa/raku/ch-1.raku59
-rw-r--r--challenge-253/massa/raku/ch-2.raku87
-rw-r--r--challenge-254/massa/raku/ch-1.raku68
-rw-r--r--challenge-254/massa/raku/ch-2.raku67
4 files changed, 281 insertions, 0 deletions
diff --git a/challenge-253/massa/raku/ch-1.raku b/challenge-253/massa/raku/ch-1.raku
new file mode 100644
index 0000000000..6b665ca6a6
--- /dev/null
+++ b/challenge-253/massa/raku/ch-1.raku
@@ -0,0 +1,59 @@
+#! /usr/bin/env raku
+
+# Perl Weekly Challenge
+# © 2023 Shimon Bollinger. All rights reserved.
+# Last modified: Mon 15 May 2023 09:17:32 PM EDT
+# Version 0.0.1
+
+=begin pod
+=TITLE
+=head2 Task 1: Split Strings
+
+=SUBTITLE
+=head2 Submitted by massa
+
+=CHALLENGE
+=head2
+
+You are given an array of strings and a character separator.
+
+Write a script to return all words separated by the given character excluding
+empty string.
+
+=head3 Example 1:
+
+ Input: @words = ("one.two.three","four.five","six")
+ $separator = "."
+ Output: "one","two","three","four","five","six"
+
+=head3 Example 2:
+
+ Input: @words = ("$perl$$", "$$raku$")
+ $separator = "$"
+ Output: "perl","raku"
+
+=SOLUTION
+
+=end pod
+
+# always use the latest version of Raku
+use v6.*;
+
+sub SOLUTION($sep, @_) {
+ @_.map(*.split($sep, :skip-empty).Slip)
+}
+
+multi MAIN (Bool :$test!) {
+ use Testo;
+
+ my @tests =
+ %{ input => \( '.', ( 'one.two.three', 'four.five', 'six' ) ),
+ output => ( "one","two","three","four","five","six" ) },
+ %{ input => \( '$', ( '$perl$$', '$$raku$' ) ),
+ output => ( 'perl', 'raku' ) },
+ ;
+
+ SOLUTION(|.<input>).&is: .<output>, .<text> for @tests
+} # end of multi MAIN (Bool :$test!)
+
+
diff --git a/challenge-253/massa/raku/ch-2.raku b/challenge-253/massa/raku/ch-2.raku
new file mode 100644
index 0000000000..838c5bf822
--- /dev/null
+++ b/challenge-253/massa/raku/ch-2.raku
@@ -0,0 +1,87 @@
+#! /usr/bin/env raku
+
+# Perl Weekly Challenge
+# © 2023 Shimon Bollinger. All rights reserved.
+# Last modified: Mon 15 May 2023 09:17:32 PM EDT
+# Version 0.0.1
+
+=begin pod
+=TITLE
+=head2 Task 2: Weakest Rows
+
+=SUBTITLE
+=head2 Submitted by massa
+
+=CHALLENGE
+=head2
+
+You are given an m x n binary matrix i.e. only 0 and 1 where 1 always appear before 0.
+
+A row i is weaker than a row j if one of the following is true:
+
+ a) The number of 1s in row i is less than the number of 1s in row j.
+ b) Both rows have the same number of 1 and i < j.
+
+Write a script to return the order of rows from weakest to strongest.
+
+=head3 Example 1:
+
+ Input: $matrix = [
+ [1, 1, 0, 0, 0],
+ [1, 1, 1, 1, 0],
+ [1, 0, 0, 0, 0],
+ [1, 1, 0, 0, 0],
+ [1, 1, 1, 1, 1]
+ ]
+ Output: (2, 0, 3, 1, 4)
+
+ The number of 1s in each row is:
+ - Row 0: 2
+ - Row 1: 4
+ - Row 2: 1
+ - Row 3: 2
+ - Row 4: 5
+
+=head3 Example 2:
+
+ Input: $matrix = [
+ [1, 0, 0, 0],
+ [1, 1, 1, 1],
+ [1, 0, 0, 0],
+ [1, 0, 0, 0]
+ ]
+ Output: (0, 2, 3, 1)
+
+ The number of 1s in each row is:
+ - Row 0: 1
+ - Row 1: 4
+ - Row 2: 1
+ - Row 3: 1
+
+=SOLUTION
+
+=end pod
+
+# always use the latest version of Raku
+use v6.*;
+
+sub SOLUTION(@matrix) {
+ @matrix».sum.pairs.sort( { $^a.value <=> $^b.value || $^a.key <=> $^b.key } )».key
+}
+
+multi MAIN (Bool :$test!) {
+ use Testo;
+
+ my @tests =
+ %{ input => [
+ [1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1]
+ ], output => (2, 0, 3, 1, 4) },
+ %{ input => [
+ [1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0]
+ ], output => (0, 2, 3, 1) },
+ ;
+
+ .<input>.&SOLUTION.&is: .<output>, .<text> for @tests
+} # end of multi MAIN (Bool :$test!)
+
+
diff --git a/challenge-254/massa/raku/ch-1.raku b/challenge-254/massa/raku/ch-1.raku
new file mode 100644
index 0000000000..2cd6a3f23f
--- /dev/null
+++ b/challenge-254/massa/raku/ch-1.raku
@@ -0,0 +1,68 @@
+#! /usr/bin/env raku
+
+# Perl Weekly Challenge
+# © 2023 Shimon Bollinger. All rights reserved.
+# Last modified: Mon 15 May 2023 09:17:32 PM EDT
+# Version 0.0.1
+
+=begin pod
+=TITLE
+=head2 Task 1: Three Power
+
+=SUBTITLE
+=head2 Submitted by massa
+
+=CHALLENGE
+=head2
+
+You are given a positive integer, $n.
+
+Write a script to return true if the given integer is a power of three
+otherwise return false.
+
+=head3 Example 1:
+
+ Input: $n = 27
+ Output: true
+
+ 27 = 3 ^ 3
+
+=head3 Example 2:
+
+ Input: $n = 0
+ Output: true
+
+ 0 = 0 ^ 3
+
+=head3 Example 3:
+
+ Input: $n = 6
+ Output: false
+
+=SOLUTION
+
+=end pod
+
+# always use the latest version of Raku
+use v6.*;
+
+sub SOLUTION($n) {
+ (^∞).map(3 ** *).first(* >= $n) == $n
+}
+
+multi MAIN (Bool :$test!) {
+ use Testo;
+
+ my @tests =
+ %{ input => 27,
+ output => True },
+ %{ input => 0,
+ output => False },
+ %{ input => 6,
+ output => False },
+ ;
+
+ .<input>.&SOLUTION.&is-eqv: .<output>, .<text> for @tests
+} # end of multi MAIN (Bool :$test!)
+
+
diff --git a/challenge-254/massa/raku/ch-2.raku b/challenge-254/massa/raku/ch-2.raku
new file mode 100644
index 0000000000..0aaf2ad34c
--- /dev/null
+++ b/challenge-254/massa/raku/ch-2.raku
@@ -0,0 +1,67 @@
+#! /usr/bin/env raku
+
+# Perl Weekly Challenge
+# © 2023 Shimon Bollinger. All rights reserved.
+# Last modified: Mon 15 May 2023 09:17:32 PM EDT
+# Version 0.0.1
+
+=begin pod
+=TITLE
+=head2 Task 2: Reverse Vowels
+
+=SUBTITLE
+=head2 Submitted by massa
+
+=CHALLENGE
+=head2
+
+You are given a string, $s.
+
+Write a script to reverse all the vowels (a, e, i, o, u) in the given string.
+
+=head3 Example 1:
+
+ Input => "Raku"
+ Output => "Ruka"
+
+=head3 Example 2:
+
+ Input => "Perl"
+ Output => "Perl"
+
+=head3 Example 3:
+
+ Input => "Julia"
+ Output => "Jaliu"
+
+=head3 Example 4:
+
+ Input => "Uiua"
+ Output => "Auiu"
+
+=SOLUTION
+
+=end pod
+
+# always use the latest version of Raku
+use v6.*;
+
+sub SOLUTION($_) {
+ my @reversed-vowels = .lc.flip.comb.grep: /<[aeiou]>/;
+ .lc.comb.map({ /<[aeiou]>/ ?? @reversed-vowels.shift !! $_ }).join.samecase($_)
+}
+
+multi MAIN (Bool :$test!) {
+ use Testo;
+
+ my @tests =
+ %{ input => "Raku", output => "Ruka" },
+ %{ input => "Perl", output => "Perl" },
+ %{ input => "Julia", output => "Jaliu" },
+ %{ input => "Uiua", output => "Auiu" },
+ ;
+
+ .<input>.&SOLUTION.&is-eqv: .<output>, .<text> for @tests
+} # end of multi MAIN (Bool :$test!)
+
+