diff options
| author | Michael Manring <michael@manring> | 2024-03-26 11:51:55 +1100 |
|---|---|---|
| committer | Michael Manring <michael@manring> | 2024-03-26 11:51:55 +1100 |
| commit | 4ce98ecb26dcf152766e02c7f31492eb9e6d9eb7 (patch) | |
| tree | 34ac63f9e16939954a0ca28ce0ab2b5a0b906f09 /challenge-262/pokgopun/python/ch-1.py | |
| parent | 041fe9129e3ef4d86df461a0feeee1b3740d5758 (diff) | |
| download | perlweeklychallenge-club-4ce98ecb26dcf152766e02c7f31492eb9e6d9eb7.tar.gz perlweeklychallenge-club-4ce98ecb26dcf152766e02c7f31492eb9e6d9eb7.tar.bz2 perlweeklychallenge-club-4ce98ecb26dcf152766e02c7f31492eb9e6d9eb7.zip | |
pwc262 solution in python
Diffstat (limited to 'challenge-262/pokgopun/python/ch-1.py')
| -rw-r--r-- | challenge-262/pokgopun/python/ch-1.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/challenge-262/pokgopun/python/ch-1.py b/challenge-262/pokgopun/python/ch-1.py new file mode 100644 index 0000000000..e2d03ff95f --- /dev/null +++ b/challenge-262/pokgopun/python/ch-1.py @@ -0,0 +1,60 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-262/ +""" + +Task 1: Max Positive Negative + +Submitted by: [46]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 + +Task 2: Count Equal Divisible +""" +### solution by pokgopun@gmail.com + +def mpn(ints: tuple): + n = sum(1 for i in ints if i < 0) + return max(n, len(ints) - n) + +import unittest + +class TestMpn(unittest.TestCase): + def test(self): + for inpt, otpt in { + (-3, 1, 2, -1, 3, -2, 4): 4, + (-1, -2, -3, 1): 3, + (1,2): 2, + }.items(): + self.assertEqual(mpn(inpt),otpt) + +unittest.main() |
