diff options
| author | WmMonty <montgomery.west@gmail.com> | 2020-08-15 11:59:59 -0700 |
|---|---|---|
| committer | WmMonty <montgomery.west@gmail.com> | 2020-08-15 11:59:59 -0700 |
| commit | ee9e6b3c971f57f5c758efad3493f42653d05239 (patch) | |
| tree | 8f68ff615f7fd0a3688cbb942aa4f236f4022183 | |
| parent | d8769ce3ed43dbdca5a41b3c17a7d27284be2cef (diff) | |
| parent | 456eb7dc260633ef022838f75a1e6e1a8322ad47 (diff) | |
| download | perlweeklychallenge-club-ee9e6b3c971f57f5c758efad3493f42653d05239.tar.gz perlweeklychallenge-club-ee9e6b3c971f57f5c758efad3493f42653d05239.tar.bz2 perlweeklychallenge-club-ee9e6b3c971f57f5c758efad3493f42653d05239.zip | |
Merge remote-tracking branch 'upstream/master'
| -rw-r--r-- | challenge-073/walt-mankowski/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-073/walt-mankowski/perl/ch-1.pl | 30 | ||||
| -rw-r--r-- | challenge-073/walt-mankowski/perl/ch-2.pl | 41 | ||||
| -rw-r--r-- | challenge-073/walt-mankowski/python/.python-version | 2 | ||||
| -rw-r--r-- | challenge-073/walt-mankowski/python/ch-1.py | 6 | ||||
| -rw-r--r-- | challenge-073/walt-mankowski/python/ch-2.py | 11 |
6 files changed, 90 insertions, 1 deletions
diff --git a/challenge-073/walt-mankowski/blog.txt b/challenge-073/walt-mankowski/blog.txt new file mode 100644 index 0000000000..b9e1cfc272 --- /dev/null +++ b/challenge-073/walt-mankowski/blog.txt @@ -0,0 +1 @@ +http://www.mawode.com/blog/blog/2020/08/15/perl-weekly-challenge-73/ diff --git a/challenge-073/walt-mankowski/perl/ch-1.pl b/challenge-073/walt-mankowski/perl/ch-1.pl new file mode 100644 index 0000000000..33adfc4de6 --- /dev/null +++ b/challenge-073/walt-mankowski/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use feature qw(:5.32); +use experimental qw(signatures); +use List::Util qw(min); + +# TASK #1 › Min Sliding Window +# Submitted by: Mohammad S Anwar + +# You are given an array of integers @A and sliding window size $S. + +# Write a script to create an array of min from each sliding window. +# Example +# Input: @A = (1, 5, 0, 2, 9, 3, 7, 6, 4, 8) and $S = 3 +# Output: (0, 0, 0, 2, 3, 3, 4, 4) + +# [(1 5 0) 2 9 3 7 6 4 8] = Min (0) +# [1 (5 0 2) 9 3 7 6 4 8] = Min (0) +# [1 5 (0 2 9) 3 7 6 4 8] = Min (0) +# [1 5 0 (2 9 3) 7 6 4 8] = Min (2) +# [1 5 0 2 (9 3 7) 6 4 8] = Min (3) +# [1 5 0 2 9 (3 7 6) 4 8] = Min (3) +# [1 5 0 2 9 3 (7 6 4) 8] = Min (4) +# [1 5 0 2 9 3 7 (6 4 8)] = Min (4) + +my @a = @ARGV; +my $s = pop @a; +my @out = map { min @a[$_..$_+$s-1] } 0..(@a-$s); +say "@out"; diff --git a/challenge-073/walt-mankowski/perl/ch-2.pl b/challenge-073/walt-mankowski/perl/ch-2.pl new file mode 100644 index 0000000000..e48e92f66f --- /dev/null +++ b/challenge-073/walt-mankowski/perl/ch-2.pl @@ -0,0 +1,41 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use feature qw(:5.32); +use experimental qw(signatures); + +# TASK #2 › Smallest Neighbour +# Submitted by: Mohammad S Anwar +# +# You are given an array of integers @A. +# +# Write a script to create an array that represents the smallest element to the left of each corresponding index. If none found then use 0. +# +# Example 1 +# Input: @A = (7, 8, 3, 12, 10) +# Output: (0, 7, 0, 3, 3) +# +# For index 0, the smallest number to the left of $A[0] i.e. 7 is none, so we put 0. +# For index 1, the smallest number to the left of $A[1] as compare to 8, in (7) is 7 so we put 7. +# For index 2, the smallest number to the left of $A[2] as compare to 3, in (7, 8) is none, so we put 0. +# For index 3, the smallest number to the left of $A[3] as compare to 12, in (7, 8, 3) is 3, so we put 3. +# For index 4, the smallest number to the left of $A[4] as compare to 10, in (7, 8, 3, 12) is 3, so we put 3 again. +# +# Example 2 +# Input: @A = (4, 6, 5) +# Output: (0, 4, 4) +# +# For index 0, the smallest number to the left of $A[0] is none, so we put 0. +# For index 1, the smallest number to the left of $A[1] as compare to 6, in (4) is 4, so we put 4. +# For index 2, the smallest number to the left of $A[2] as compare to 5, in (4, 6) is 4, so we put 4 again. + +my @A = @ARGV; +my @output = (0); +my $min = $A[0]; + +for my $x (@A[1..$#A]) { + push @output, $min < $x ? $min : 0; + $min = $x if $x < $min; +} + +say "@output"; diff --git a/challenge-073/walt-mankowski/python/.python-version b/challenge-073/walt-mankowski/python/.python-version index ff313b8c21..0cbfaed0d9 100644 --- a/challenge-073/walt-mankowski/python/.python-version +++ b/challenge-073/walt-mankowski/python/.python-version @@ -1 +1 @@ -3.8.4 +3.8.5 diff --git a/challenge-073/walt-mankowski/python/ch-1.py b/challenge-073/walt-mankowski/python/ch-1.py new file mode 100644 index 0000000000..b3a75b89fa --- /dev/null +++ b/challenge-073/walt-mankowski/python/ch-1.py @@ -0,0 +1,6 @@ +from sys import argv + +a = [int(x) for x in argv[1:]] +s = a.pop() +out = [min(a[i:i+s]) for i in range(len(a)-s)] +print(out) diff --git a/challenge-073/walt-mankowski/python/ch-2.py b/challenge-073/walt-mankowski/python/ch-2.py new file mode 100644 index 0000000000..00ce682c69 --- /dev/null +++ b/challenge-073/walt-mankowski/python/ch-2.py @@ -0,0 +1,11 @@ +from sys import argv + +a = [int(x) for x in argv[1:]] +output = [0] +curmin = a[0] + +for x in a[1:]: + output.append(curmin if curmin < x else 0) + curmin = min(curmin, x) + +print(output) |
