aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2023-05-19 18:30:24 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2023-05-19 18:30:24 +0100
commit12216a3eeb12eb503cf88c4d6ffc298848076304 (patch)
tree5f0e4ebe05d502924acce835ed54d4c0343596a1
parentfc7ef68e2e6290ce18d41de4ea3b78971224e012 (diff)
downloadperlweeklychallenge-club-12216a3eeb12eb503cf88c4d6ffc298848076304.tar.gz
perlweeklychallenge-club-12216a3eeb12eb503cf88c4d6ffc298848076304.tar.bz2
perlweeklychallenge-club-12216a3eeb12eb503cf88c4d6ffc298848076304.zip
Add Perl solution
-rw-r--r--challenge-216/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-217/paulo-custodio/Makefile2
-rw-r--r--challenge-217/paulo-custodio/perl/ch-1.pl37
-rw-r--r--challenge-217/paulo-custodio/perl/ch-2.pl49
-rw-r--r--challenge-217/paulo-custodio/t/test-1.yaml15
-rw-r--r--challenge-217/paulo-custodio/t/test-2.yaml25
6 files changed, 128 insertions, 2 deletions
diff --git a/challenge-216/paulo-custodio/perl/ch-2.pl b/challenge-216/paulo-custodio/perl/ch-2.pl
index 7c31c839e1..290dffedd9 100644
--- a/challenge-216/paulo-custodio/perl/ch-2.pl
+++ b/challenge-216/paulo-custodio/perl/ch-2.pl
@@ -80,5 +80,3 @@ sub count_stickers {
}
say count_stickers(@ARGV);
-
-
diff --git a/challenge-217/paulo-custodio/Makefile b/challenge-217/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-217/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-217/paulo-custodio/perl/ch-1.pl b/challenge-217/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..e3d1c555f9
--- /dev/null
+++ b/challenge-217/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+
+# Challenge 217
+#
+# Task 1: Sorted Matrix
+# Submitted by: Mohammad S Anwar
+#
+# You are given a n x n matrix where n >= 2.
+#
+# Write a script to find 3rd smallest element in the sorted matrix.
+# Example 1
+#
+# Input: @matrix = ([3, 1, 2], [5, 2, 4], [0, 1, 3])
+# Output: 1
+#
+# The sorted list of the given matrix: 0, 1, 1, 2, 2, 3, 3, 4, 5.
+# The 3rd smallest of the sorted list is 1.
+#
+# Example 2
+#
+# Input: @matrix = ([2, 1], [4, 5])
+# Output: 4
+#
+# The sorted list of the given matrix: 1, 2, 4, 5.
+# The 3rd smallest of the sorted list is 4.
+#
+# Example 3
+#
+# Input: @matrix = ([1, 0, 3], [0, 0, 0], [1, 2, 1])
+# Output: 0
+#
+# The sorted list of the given matrix: 0, 0, 0, 0, 1, 1, 1, 2, 3.
+# The 3rd smallest of the sorted list is 0.
+
+use Modern::Perl;
+
+say((sort {$a<=>$b} split ' ', "@ARGV" =~ s/\D/ /gr)[2]);
diff --git a/challenge-217/paulo-custodio/perl/ch-2.pl b/challenge-217/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..dadcc0ef29
--- /dev/null
+++ b/challenge-217/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/env perl
+
+# Challenge 217
+#
+# Task 2: Max Number
+# Submitted by: Mohammad S Anwar
+#
+# You are given a list of positive integers.
+#
+# Write a script to concatenate the integers to form the highest possible value.
+# Example 1:
+#
+# Input: @list = (1, 23)
+# Output: 231
+#
+# Example 2:
+#
+# Input: @list = (10, 3, 2)
+# Output: 3210
+#
+# Example 3:
+#
+# Input: @list = (31, 2, 4, 10)
+# Output: 431210
+#
+# Example 4:
+#
+# Input: @list = (5, 11, 4, 1, 2)
+# Output: 542111
+#
+# Example 5:
+#
+# Input: @list = (1, 10)
+# Output: 110
+
+use Modern::Perl;
+
+sub by_largest {
+ my($a, $b) = @_;
+
+ if (substr($a,0,1) ne substr($b,0,1)) {
+ return $b cmp $a;
+ }
+ else {
+ return length($a) <=> length($b);
+ }
+}
+
+say join '', sort {by_largest($a,$b)} @ARGV;
diff --git a/challenge-217/paulo-custodio/t/test-1.yaml b/challenge-217/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..1795b47ab2
--- /dev/null
+++ b/challenge-217/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,15 @@
+- setup:
+ cleanup:
+ args: "'([3, 1, 2], [5, 2, 4], [0, 1, 3])'"
+ input:
+ output: 1
+- setup:
+ cleanup:
+ args: "'([2, 1], [4, 5])'"
+ input:
+ output: 4
+- setup:
+ cleanup:
+ args: "'([1, 0, 3], [0, 0, 0], [1, 2, 1])'"
+ input:
+ output: 0
diff --git a/challenge-217/paulo-custodio/t/test-2.yaml b/challenge-217/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..2ebfc063cb
--- /dev/null
+++ b/challenge-217/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,25 @@
+- setup:
+ cleanup:
+ args: 1 23
+ input:
+ output: 231
+- setup:
+ cleanup:
+ args: 10 3 2
+ input:
+ output: 3210
+- setup:
+ cleanup:
+ args: 31 2 4 10
+ input:
+ output: 431210
+- setup:
+ cleanup:
+ args: 5 11 4 1 2
+ input:
+ output: 542111
+- setup:
+ cleanup:
+ args: 1 10
+ input:
+ output: 110