aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)