aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-242/solathian/ch-1.pl31
-rw-r--r--challenge-242/solathian/ch-2.pl18
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-242/solathian/ch-1.pl b/challenge-242/solathian/ch-1.pl
new file mode 100644
index 0000000000..591cf70b5a
--- /dev/null
+++ b/challenge-242/solathian/ch-1.pl
@@ -0,0 +1,31 @@
+#!usr/bin/perl
+use v5.38;
+no warnings 'deprecated'; # giving smartmatch some love
+# Challenge 242 - 1 - Missing Members
+
+
+missingMembers([1, 2, 3], [2, 4, 6]); # Output: ([1, 3], [4, 6])
+missingMembers([1, 2, 3, 3], [1, 1, 2, 2]); # Output: ([3])
+
+
+
+sub missingMembers($arrRef1, $arrRef2)
+{
+ my @missing1;
+ my @missing2;
+
+ foreach my $elem (@$arrRef1)
+ {
+ next if($elem ~~ @$arrRef2);
+ push( @missing1, $elem) unless($elem ~~ @missing1)
+ }
+
+ foreach my $elem (@$arrRef2)
+ {
+ next if($elem ~~ @$arrRef1);
+ push( @missing2, $elem) unless($elem ~~ @missing2)
+ }
+
+ say("([", join(', ', @missing1 ), "], [", join(', ', @missing2 ), "])");
+
+} \ No newline at end of file
diff --git a/challenge-242/solathian/ch-2.pl b/challenge-242/solathian/ch-2.pl
new file mode 100644
index 0000000000..0e061ca0d6
--- /dev/null
+++ b/challenge-242/solathian/ch-2.pl
@@ -0,0 +1,18 @@
+#!usr/bin/perl
+use v5.38;
+use Data::Dumper;
+# Challenge 242 - 2 - Flip Matrix
+
+
+flip( [[1, 1, 0], [1, 0, 1], [0, 0, 0]]); # ([1, 0, 0], [0, 1, 0], [1, 1, 1])
+flip( [[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]]); #([1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0])
+
+sub flip($listRef)
+{
+ foreach my $rowRef (@$listRef)
+ {
+ @$rowRef = map{($_ == 0) ? 1 : 0 } reverse @$rowRef;
+ }
+
+ say Dumper $listRef;
+} \ No newline at end of file