aboutsummaryrefslogtreecommitdiff
path: root/challenge-262/spadacciniweb/python
diff options
context:
space:
mode:
authorrir <rirans@comcast.net>2024-03-30 08:53:54 -0400
committerGitHub <noreply@github.com>2024-03-30 08:53:54 -0400
commit28af4e6c7bc7a561f74a6aea4ebefb89612b04ef (patch)
treebc42c63e6e7b9e77b40872e6226356c75e7e2bbd /challenge-262/spadacciniweb/python
parent293ea7e2fde6cf20c1e0f1140fe5e5574487c544 (diff)
parent286052e238cd08089167db24b9bc2cb5c2f434d2 (diff)
downloadperlweeklychallenge-club-28af4e6c7bc7a561f74a6aea4ebefb89612b04ef.tar.gz
perlweeklychallenge-club-28af4e6c7bc7a561f74a6aea4ebefb89612b04ef.tar.bz2
perlweeklychallenge-club-28af4e6c7bc7a561f74a6aea4ebefb89612b04ef.zip
Merge branch 'manwar:master' into work
Diffstat (limited to 'challenge-262/spadacciniweb/python')
-rw-r--r--challenge-262/spadacciniweb/python/ch-1.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-262/spadacciniweb/python/ch-1.py b/challenge-262/spadacciniweb/python/ch-1.py
new file mode 100644
index 0000000000..d9782dc03a
--- /dev/null
+++ b/challenge-262/spadacciniweb/python/ch-1.py
@@ -0,0 +1,49 @@
+# Task 1: Max Positive Negative
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given an array of integers, @ints.
+# Write a script to return the maximum number of either positive or negative integers in the given array.
+#
+# Example 1
+# Input: @ints = (-3, 1, 2, -1, 3, -2, 4)
+# Output: 4
+#
+# Count of positive integers: 4
+# Count of negative integers: 3
+# Maximum of count of positive and negative integers: 4
+#
+# Example 2
+# Input: @ints = (-1, -2, -3, 1)
+# Output: 3
+#
+# Count of positive integers: 1
+# Count of negative integers: 3
+# Maximum of count of positive and negative integers: 3
+#
+# Example 3
+# Input: @ints = (1,2)
+# Output: 2
+#
+# Count of positive integers: 2
+# Count of negative integers: 0
+# Maximum of count of positive and negative integers: 2
+
+def maximum_of_positive_and_negative(ints):
+ negative = len(list(filter(lambda x: (x < 0), ints)))
+ positive = len(list(filter(lambda x: (x > 0), ints)))
+
+ print("(%s) -> %d" %
+ ( ",".join(map(str, ints)),
+ max(positive, negative)
+ )
+ )
+
+if __name__ == "__main__":
+ ints = [-3, 1, 2, -1, 3, -2, 4]
+ maximum_of_positive_and_negative(ints)
+
+ ints = [-1, -2, -3, 1]
+ maximum_of_positive_and_negative(ints)
+
+ ints = [1,2]
+ maximum_of_positive_and_negative(ints)