aboutsummaryrefslogtreecommitdiff
path: root/challenge-320/packy-anderson/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-320/packy-anderson/python/ch-1.py')
-rwxr-xr-xchallenge-320/packy-anderson/python/ch-1.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-320/packy-anderson/python/ch-1.py b/challenge-320/packy-anderson/python/ch-1.py
new file mode 100755
index 0000000000..8e103a1509
--- /dev/null
+++ b/challenge-320/packy-anderson/python/ch-1.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+def maxCount(ints):
+ pos = 0
+ neg = 0
+ for int in ints:
+ if int > 0:
+ pos += 1
+ elif int < 0:
+ neg +=1
+ max_count = max(pos, neg)
+ explain = (
+ f"There are {pos} positive integers.\n" +
+ f"There are {neg} negative integers.\n" +
+ f"The maximum between {pos} and {neg} is {max_count}."
+ )
+ return max_count, explain
+
+def comma_join(arr):
+ return ', '.join(map(lambda i: str(i), arr))
+
+def solution(ints):
+ print(f'Input: @ints = ({comma_join(ints)})')
+ max_count, explain = maxCount(ints)
+ print(f'Output: {max_count}\n\n{explain}')
+
+print('Example 1:')
+solution([-3, -2, -1, 1, 2, 3])
+
+print('\nExample 2:')
+solution([-2, -1, 0, 0, 1])
+
+print('\nExample 3:')
+solution([1, 2, 3, 4])