aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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");