aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-29 06:59:18 +0100
committerGitHub <noreply@github.com>2020-09-29 06:59:18 +0100
commit4dd643cc2afa395ea9e54eac857d002eb9016018 (patch)
tree5f571520d0c6e057268047afab855bfecdfaac9b
parent07c8ff0f43c1168cce222b3e3d1c9665dd1c3c2e (diff)
parent44e8990c7371fbbdabe1fe5924a3484031b374e6 (diff)
downloadperlweeklychallenge-club-4dd643cc2afa395ea9e54eac857d002eb9016018.tar.gz
perlweeklychallenge-club-4dd643cc2afa395ea9e54eac857d002eb9016018.tar.bz2
perlweeklychallenge-club-4dd643cc2afa395ea9e54eac857d002eb9016018.zip
Merge pull request #2404 from waltman/branch-for-challenge-080
Branch for challenge 080
-rw-r--r--challenge-080/walt-mankowski/blog.txt1
-rw-r--r--challenge-080/walt-mankowski/perl/ch-1.pl24
-rw-r--r--challenge-080/walt-mankowski/perl/ch-2.pl33
-rw-r--r--challenge-080/walt-mankowski/python/ch-1.py11
-rw-r--r--challenge-080/walt-mankowski/python/ch-2.py16
5 files changed, 85 insertions, 0 deletions
diff --git a/challenge-080/walt-mankowski/blog.txt b/challenge-080/walt-mankowski/blog.txt
new file mode 100644
index 0000000000..ddc25b9fc7
--- /dev/null
+++ b/challenge-080/walt-mankowski/blog.txt
@@ -0,0 +1 @@
+http://www.mawode.com/blog/blog/2020/09/28/perl-weekly-challenge-80/
diff --git a/challenge-080/walt-mankowski/perl/ch-1.pl b/challenge-080/walt-mankowski/perl/ch-1.pl
new file mode 100644
index 0000000000..dd356e9bee
--- /dev/null
+++ b/challenge-080/walt-mankowski/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use feature qw(:5.32);
+use experimental qw(signatures);
+
+# TASK #1 › Smallest Positive Number Bits
+# Submitted by: Mohammad S Anwar
+#
+# You are given unsorted list of integers @N.
+#
+# Write a script to find out the smallest positive number missing.
+
+my %n = map { $_ => 1 } @ARGV;
+
+my $i = 1;
+while (1) {
+ if (defined $n{$i}) {
+ $i++;
+ } else {
+ say $i;
+ last;
+ }
+}
diff --git a/challenge-080/walt-mankowski/perl/ch-2.pl b/challenge-080/walt-mankowski/perl/ch-2.pl
new file mode 100644
index 0000000000..d81887113b
--- /dev/null
+++ b/challenge-080/walt-mankowski/perl/ch-2.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use feature qw(:5.32);
+use experimental qw(signatures);
+
+# TASK #2 › Count Candies
+# Submitted by: Mohammad S Anwar
+#
+# You are given rankings of @N candidates.
+#
+# Write a script to find out the total candies needed for all
+# candidates. You are asked to follow the rules below:
+#
+# a) You must given at least one candy to each candidate.
+#
+# b) Candidate with higher ranking get more candies than their
+# immediate neighbors on either side.
+
+my @n = @ARGV;
+my $candy = @n;
+
+# right neighbors
+for my $i (0..$#n-1) {
+ $candy++ if $n[$i] > $n[$i+1];
+}
+
+# left neighbors
+for my $i (1..$#n) {
+ $candy++ if $n[$i] > $n[$i-1];
+}
+
+say $candy;
diff --git a/challenge-080/walt-mankowski/python/ch-1.py b/challenge-080/walt-mankowski/python/ch-1.py
new file mode 100644
index 0000000000..0972720949
--- /dev/null
+++ b/challenge-080/walt-mankowski/python/ch-1.py
@@ -0,0 +1,11 @@
+from sys import argv
+
+n = { int(x) for x in argv[1:] }
+
+i = 1
+while (True):
+ if i in n:
+ i += 1
+ else:
+ print(i)
+ break
diff --git a/challenge-080/walt-mankowski/python/ch-2.py b/challenge-080/walt-mankowski/python/ch-2.py
new file mode 100644
index 0000000000..15346a1a41
--- /dev/null
+++ b/challenge-080/walt-mankowski/python/ch-2.py
@@ -0,0 +1,16 @@
+from sys import argv
+
+n = [int(x) for x in argv[1:]]
+candy = len(n)
+
+# right neighbors
+for i in range(len(n)-1):
+ if n[i] > n[i+1]:
+ candy += 1
+
+# left neighbors
+for i in range(1, len(n)):
+ if n[i] > n[i-1]:
+ candy += 1
+
+print(candy)