diff options
| -rw-r--r-- | challenge-332/pokgopun/python/ch-1.py | 46 | ||||
| -rw-r--r-- | challenge-332/pokgopun/python/ch-2.py | 66 |
2 files changed, 112 insertions, 0 deletions
diff --git a/challenge-332/pokgopun/python/ch-1.py b/challenge-332/pokgopun/python/ch-1.py new file mode 100644 index 0000000000..d2f149280f --- /dev/null +++ b/challenge-332/pokgopun/python/ch-1.py @@ -0,0 +1,46 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-332/ +""" + +Task 1: Binary Date + +Submitted by: [39]Mohammad Sajid Anwar + __________________________________________________________________ + + You are given a date in the format YYYY-MM-DD. + + Write a script to convert it into binary date. + +Example 1 + +Input: $date = "2025-07-26" +Output: "11111101001-111-11010" + +Example 2 + +Input: $date = "2000-02-02" +Output: "11111010000-10-10" + +Example 3 + +Input: $date = "2024-12-31" +Output: "11111101000-1100-11111" + +Task 2: Odd Letters +""" +### solution by pokgopun@gmail.com + +def bd(string: str) -> str: + return "-".join(bin(int(e))[2:] for e in string.split("-")) + +import unittest + +class TestBd(unittest.TestCase): + def test(self): + for inpt, otpt in { + "2025-07-26": "11111101001-111-11010", + "2000-02-02": "11111010000-10-10", + "2024-12-31": "11111101000-1100-11111", + }.items(): + self.assertEqual(bd(inpt),otpt) + +unittest.main() diff --git a/challenge-332/pokgopun/python/ch-2.py b/challenge-332/pokgopun/python/ch-2.py new file mode 100644 index 0000000000..15feb6a40d --- /dev/null +++ b/challenge-332/pokgopun/python/ch-2.py @@ -0,0 +1,66 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-332/ +""" + +Task 2: Odd Letters + +Submitted by: [40]Mohammad Sajid Anwar + __________________________________________________________________ + + You are given a string. + + Write a script to find out if each letter in the given string appeared + odd number of times. + +Example 1 + +Input: $str = "weekly" +Output: false + +w: 1 time +e: 2 times +k: 1 time +l: 1 time +y: 1 time + +The letter 'e' appeared 2 times i.e. even. + +Example 2 + +Input: $str = "perl" +Output: true + +Example 3 + +Input: $source = "challenge" +Output: false + __________________________________________________________________ + + Last date to submit the solution 23:59 (UK Time) Sunday 3rd August + 2025. + __________________________________________________________________ + +SO WHAT DO YOU THINK ? +""" +### solution by pokgopun@gmail.com + +def ol(string: str) -> bool: + cc: dict[str,int] = {} + for c in string: + cc[c] = cc.get(c,0) + 1 + for v in cc.values(): + if v % 2 == 0: + return False + return True + +import unittest + +class TestOl(unittest.TestCase): + def test(self): + for inpt, otpt in { + "weekly": False, + "perl": True, + "challenge": False, + }.items(): + self.assertEqual(ol(inpt),otpt) + +unittest.main() |
