aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-078/walt-mankowski/blog.txt1
-rw-r--r--challenge-078/walt-mankowski/perl/ch-1.pl39
-rw-r--r--challenge-078/walt-mankowski/perl/ch-2.pl28
-rw-r--r--challenge-078/walt-mankowski/python/ch-1.py12
-rw-r--r--challenge-078/walt-mankowski/python/ch-2.py10
5 files changed, 90 insertions, 0 deletions
diff --git a/challenge-078/walt-mankowski/blog.txt b/challenge-078/walt-mankowski/blog.txt
new file mode 100644
index 0000000000..11dea55250
--- /dev/null
+++ b/challenge-078/walt-mankowski/blog.txt
@@ -0,0 +1 @@
+http://www.mawode.com/blog/blog/2020/09/14/perl-weekly-challenge-78/
diff --git a/challenge-078/walt-mankowski/perl/ch-1.pl b/challenge-078/walt-mankowski/perl/ch-1.pl
new file mode 100644
index 0000000000..74240b922a
--- /dev/null
+++ b/challenge-078/walt-mankowski/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use feature qw(:5.32);
+use experimental qw(signatures);
+
+# TASK #1 › Leader Element
+# Submitted by: Mohammad S Anwar
+#
+# You are given an array @A containing distinct integers.
+#
+# Write a script to find all leader elements in the array @A. Print
+# (0) if none found.
+#
+# An element is leader if it is greater than all the elements to
+# its right side.
+#
+# Example 1:
+#
+# Input: @A = (9, 10, 7, 5, 6, 1)
+# Output: (10, 7, 6, 1)
+#
+# Example 2:
+#
+# Input: @A = (3, 4, 5)
+# Output: (5)
+
+my @a = @ARGV;
+my $max;
+my @out;
+
+for (my $i = $#a; $i >= 0; $i--) {
+ if (!defined $max || $a[$i] > $max) {
+ unshift @out, $a[$i];
+ $max = $a[$i];
+ }
+}
+
+say "@out";
diff --git a/challenge-078/walt-mankowski/perl/ch-2.pl b/challenge-078/walt-mankowski/perl/ch-2.pl
new file mode 100644
index 0000000000..91095a9e6c
--- /dev/null
+++ b/challenge-078/walt-mankowski/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use feature qw(:5.32);
+use experimental qw(signatures);
+
+# TASK #2 › Left Rotation
+# Submitted by: Mohammad S Anwar
+#
+# You are given array @A containing positive numbers and @B containing
+# one or more indices from the array @A.
+#
+# Write a script to left rotate @A so that the number at the first
+# index of @B becomes the first element in the array. Similary, left
+# rotate @A again so that the number at the second index of @B becomes
+# the first element in the array.
+
+my @a = split / /, $ARGV[0];
+my @b = split / /, $ARGV[1];
+
+for my $b (@b) {
+ local $, = " ";
+ say rotate_by($b, @a);
+}
+
+sub rotate_by($b, @a) {
+ return (@a[$b..$#a], @a[0..$b-1]);
+}
diff --git a/challenge-078/walt-mankowski/python/ch-1.py b/challenge-078/walt-mankowski/python/ch-1.py
new file mode 100644
index 0000000000..48fa69fb88
--- /dev/null
+++ b/challenge-078/walt-mankowski/python/ch-1.py
@@ -0,0 +1,12 @@
+from sys import argv
+
+a = [int(x) for x in argv[1:]]
+best = None
+out = []
+
+for i in range(len(a)-1, -1, -1):
+ if best is None or a[i] > best:
+ out.insert(0, a[i])
+ best = a[i]
+
+print(out)
diff --git a/challenge-078/walt-mankowski/python/ch-2.py b/challenge-078/walt-mankowski/python/ch-2.py
new file mode 100644
index 0000000000..0d72428167
--- /dev/null
+++ b/challenge-078/walt-mankowski/python/ch-2.py
@@ -0,0 +1,10 @@
+from sys import argv
+
+def rotate_by(b, a):
+ return a[b:] + a[0:b]
+
+a = [int(x) for x in argv[1].split(' ')]
+b = [int(x) for x in argv[2].split(' ')]
+
+for x in b:
+ print(rotate_by(x, a))