diff options
Diffstat (limited to 'challenge-320/steven-wilson/python/ch-1.py')
| -rw-r--r-- | challenge-320/steven-wilson/python/ch-1.py | 27 |
1 files changed, 27 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) |
