aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-05-18 14:49:22 +0100
committerGitHub <noreply@github.com>2023-05-18 14:49:22 +0100
commit396595e581e1aeb82f71eb8df0769c7523521d07 (patch)
tree8fe7b9a50f33cb654f60e16522ba54d3bda67a10
parent56891373602edc25ecc586e42bcd3f20496512e1 (diff)
parent0fcfce2743161c670cbacf6969702e8f1794d4fc (diff)
downloadperlweeklychallenge-club-396595e581e1aeb82f71eb8df0769c7523521d07.tar.gz
perlweeklychallenge-club-396595e581e1aeb82f71eb8df0769c7523521d07.tar.bz2
perlweeklychallenge-club-396595e581e1aeb82f71eb8df0769c7523521d07.zip
Merge pull request #8098 from aut0exec/Challenge_217
Challenge 217
-rw-r--r--challenge-217/aut0exec/perl/challenge_1.pl38
-rw-r--r--challenge-217/aut0exec/perl/challenge_2.pl24
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-217/aut0exec/perl/challenge_1.pl b/challenge-217/aut0exec/perl/challenge_1.pl
new file mode 100644
index 0000000000..119f1b345e
--- /dev/null
+++ b/challenge-217/aut0exec/perl/challenge_1.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+#
+# Author: Aut0exec
+#
+# 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.
+#
+########################################################################
+
+use strict;
+use warnings;
+
+sub flatten {
+ my @matrix = ([3, 1, 2], [5, 2, 4], [0, 6, 3], [3, 4, 9]);
+ my @flattened;
+ my $matrix_len=@matrix;
+
+ for(my $row = 0; $row < $matrix_len; $row++) {
+ for(my $col = 0; $col < 3; $col++) {
+ push @flattened, "$matrix[$row][$col]";
+ }
+ }
+
+ return (sort { $a <=> $b } @flattened);
+}
+
+my @sorted = flatten();
+
+print ("The sorted list of the given matrix: @sorted\n");
+print ("The 3rd smallest of the sorted list is $sorted[2]\n");
+
+
diff --git a/challenge-217/aut0exec/perl/challenge_2.pl b/challenge-217/aut0exec/perl/challenge_2.pl
new file mode 100644
index 0000000000..3d9d0c8040
--- /dev/null
+++ b/challenge-217/aut0exec/perl/challenge_2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+#
+# Author: Aut0exec
+#
+# 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
+#
+########################################################################
+
+use strict;
+use warnings;
+
+my @list = (11, 2, 34, 65, 15, 3, 0);
+my @sorted = sort {$a <= $b} (sort { $a <=> $b} @list);
+my $list_len = @sorted;
+
+print("Output: ");
+for(my $i = 0; $i < $list_len; $i++) {
+ print("$sorted[$i]");
+}
+print("\n");