aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-05-06 17:43:32 +0100
committerGitHub <noreply@github.com>2025-05-06 17:43:32 +0100
commit8155b0e7b32c7918210367d40d14e1bd2aba174b (patch)
tree1aa23ae98adba3044ba5798ebb2b89903a7e603b
parent7d67833e2e7de682d2d418145812d575218e0fa9 (diff)
parentb4dcca2f02759b5b910bf5ef2e10f5816301d46d (diff)
downloadperlweeklychallenge-club-8155b0e7b32c7918210367d40d14e1bd2aba174b.tar.gz
perlweeklychallenge-club-8155b0e7b32c7918210367d40d14e1bd2aba174b.tar.bz2
perlweeklychallenge-club-8155b0e7b32c7918210367d40d14e1bd2aba174b.zip
Merge pull request #11989 from oWnOIzRi/week320
add solutions week 320 in python
-rw-r--r--challenge-320/steven-wilson/python/ch-1.py27
-rw-r--r--challenge-320/steven-wilson/python/ch-2.py23
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-320/steven-wilson/python/ch-1.py b/challenge-320/steven-wilson/python/ch-1.py
new file mode 100644
index 0000000000..c6f8d506f9
--- /dev/null
+++ b/challenge-320/steven-wilson/python/ch-1.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+
+def maximum_count(integers):
+ """ Given an array of integers, return the maximum between the number of
+ positive and negative integers. Zero is neither positive nor negative.
+
+ >>> maximum_count([-3, -2, -1, 1, 2, 3])
+ 3
+ >>> maximum_count([-2, -1, 0, 0, 1])
+ 2
+ >>> maximum_count([1, 2, 3, 4])
+ 4
+ """
+ (positive, negative) = (0, 0)
+ for i in integers:
+ if i > 0:
+ positive += 1
+ elif i < 0:
+ negative += 1
+ return max(positive, negative)
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod(verbose=True)
diff --git a/challenge-320/steven-wilson/python/ch-2.py b/challenge-320/steven-wilson/python/ch-2.py
new file mode 100644
index 0000000000..5c5b4cbe35
--- /dev/null
+++ b/challenge-320/steven-wilson/python/ch-2.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+
+def sum_difference(integers):
+ """ Given an array of positive integers, return the absolute difference
+ between digit sum and element sum of the given array.
+
+ >>> sum_difference([1, 23, 4, 5])
+ 18
+ >>> sum_difference([1, 2, 3, 4, 5])
+ 0
+ >>> sum_difference([1, 2, 34])
+ 27
+ """
+ element_sum = sum(integers)
+ digit_sum = sum(int(i) for i in "".join(map(str, integers)))
+ return abs(digit_sum - element_sum)
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod(verbose=True)