aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-242/massa/raku/ch-1.raku64
-rw-r--r--challenge-242/massa/raku/ch-2.raku72
2 files changed, 136 insertions, 0 deletions
diff --git a/challenge-242/massa/raku/ch-1.raku b/challenge-242/massa/raku/ch-1.raku
new file mode 100644
index 0000000000..9eacb018ce
--- /dev/null
+++ b/challenge-242/massa/raku/ch-1.raku
@@ -0,0 +1,64 @@
+#! /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: Missing Members
+
+=SUBTITLE
+=head2 Submitted by massa
+
+=CHALLENGE
+=head2
+
+You are given two arrays of integers.
+
+Write a script to find out the missing members in each other arrays.
+
+=head3 Example 1:
+
+ Input: @arr1 = (1, 2, 3)
+ @arr2 = (2, 4, 6)
+ Output: ([1, 3], [4, 6])
+
+ (1, 2, 3) has 2 members (1, 3) missing in the array (2, 4, 6).
+ (2, 4, 6) has 2 members (4, 6) missing in the array (1, 2, 3).
+
+=head3 Example 2:
+
+ Input: @arr1 = (1, 2, 3, 3)
+ @arr2 = (1, 1, 2, 2)
+ Output: ([3])
+
+ (1, 2, 3, 3) has 2 members (3, 3) missing in the array (1, 1, 2, 2). Since they are same, keep just one.
+ (1, 1, 2, 2) has 0 member missing in the array (1, 2, 3, 3).
+
+=SOLUTION
+
+=end pod
+
+# always use the latest version of Raku
+use v6.*;
+
+sub SOLUTION(@ (@a, @b)) {
+ (@a ∖ @b, @b ∖ @a)».keys».sort
+}
+
+multi MAIN (Bool :$test!) {
+ use Test;
+
+ my @tests =
+ %{ input => ((1, 2, 3), (2, 4, 6)),
+ output => ((1, 3), (4, 6)) },
+ %{ input => ((1, 2, 3, 3), (1, 1, 2, 2)),
+ output => ((3,), ()) },
+ ;
+
+ .<input>.&SOLUTION.deepmap({$_}).&is-deeply: .<output>, .<text> for @tests
+} # end of multi MAIN (Bool :$test!)
+
+
diff --git a/challenge-242/massa/raku/ch-2.raku b/challenge-242/massa/raku/ch-2.raku
new file mode 100644
index 0000000000..3241fa21c6
--- /dev/null
+++ b/challenge-242/massa/raku/ch-2.raku
@@ -0,0 +1,72 @@
+#! /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: Flip Matrix
+
+=SUBTITLE
+=head2 Submitted by massa
+
+=CHALLENGE
+=head2
+
+You are given n x n binary matrix.
+
+Write a script to flip the given matrix as below.
+
+ 1 1 0
+ 0 1 1
+ 0 0 1
+
+ a) Reverse each row
+
+ 0 1 1
+ 1 1 0
+ 1 0 0
+
+ b) Invert each member
+
+ 1 0 0
+ 0 0 1
+ 0 1 1
+
+=head3 Example 1:
+
+ Input: @matrix = ([1, 1, 0], [1, 0, 1], [0, 0, 0])
+ Output: ([1, 0, 0], [0, 1, 0], [1, 1, 1])
+
+=head3 Example 2:
+
+ Input: @matrix = ([1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0])
+ Output: ([1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0])
+
+=SOLUTION
+
+=end pod
+
+# always use the latest version of Raku
+use v6.*;
+
+sub SOLUTION(@_) {
+ @_».reverse».map: 1 - *
+}
+
+multi MAIN (Bool :$test!) {
+ use Test;
+
+ my @tests =
+ %{ input => ((1, 1, 0), (1, 0, 1), (0, 0, 0)),
+ output => ((1, 0, 0), (0, 1, 0), (1, 1, 1)) },
+ %{ input => ((1, 1, 0, 0), (1, 0, 0, 1), (0, 1, 1, 1), (1, 0, 1, 0)),
+ output => ((1, 1, 0, 0), (0, 1, 1, 0), (0, 0, 0, 1), (1, 0, 1, 0)) },
+ ;
+
+ .<input>.&SOLUTION.deepmap({$_}).&is-deeply: .<output>, .<text> for @tests
+} # end of multi MAIN (Bool :$test!)
+
+