aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-276/pokgopun/python/ch-1.py62
-rw-r--r--challenge-276/pokgopun/python/ch-2.py53
2 files changed, 115 insertions, 0 deletions
diff --git a/challenge-276/pokgopun/python/ch-1.py b/challenge-276/pokgopun/python/ch-1.py
new file mode 100644
index 0000000000..9e9f3c784f
--- /dev/null
+++ b/challenge-276/pokgopun/python/ch-1.py
@@ -0,0 +1,62 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-276/
+"""
+
+Task 1: Complete Day
+
+Submitted by: [41]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given an array of integers, @hours.
+
+ Write a script to return the number of pairs that forms a complete day.
+
+ A complete day is defined as a time duration that is an exact
+ multiple of 24 hours.
+
+Example 1
+
+Input: @hours = (12, 12, 30, 24, 24)
+Output: 2
+
+Pair 1: (12, 12)
+Pair 2: (24, 24)
+
+Example 2
+
+Input: @hours = (72, 48, 24, 5)
+Output: 3
+
+Pair 1: (72, 48)
+Pair 2: (72, 24)
+Pair 3: (48, 24)
+
+Example 3
+
+Input: @hours = (12, 18, 24)
+Output: 0
+
+Task 2: Maximum Frequency
+"""
+### solution by pokgopun@gmail.com
+
+def completeDay(hours: tuple):
+ c = 0
+ l = len(hours)
+ for i in range(l-1):
+ for j in range(i+1, l):
+ if (hours[i] + hours[j]) % 24 == 0:
+ c += 1
+ return c
+
+import unittest
+
+class TestCompleteDay(unittest.TestCase):
+ def test(self):
+ for inpt, otpt in {
+ (12, 12, 30, 24, 24): 2,
+ (72, 48, 24, 5): 3,
+ (12, 18, 24): 0,
+ }.items():
+ self.assertEqual(completeDay(inpt),otpt)
+
+unittest.main()
diff --git a/challenge-276/pokgopun/python/ch-2.py b/challenge-276/pokgopun/python/ch-2.py
new file mode 100644
index 0000000000..358fed0eb9
--- /dev/null
+++ b/challenge-276/pokgopun/python/ch-2.py
@@ -0,0 +1,53 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-276/
+"""
+
+Task 2: Maximum Frequency
+
+Submitted by: [42]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given an array of positive integers, @ints.
+
+ Write a script to return the total number of elements in the given
+ array which have the highest frequency.
+
+Example 1
+
+Input: @ints = (1, 2, 2, 4, 1, 5)
+Ouput: 4
+
+The maximum frequency is 2.
+The elements 1 and 2 has the maximum frequency.
+
+Example 2
+
+Input: @ints = (1, 2, 3, 4, 5)
+Ouput: 5
+
+The maximum frequency is 1.
+The elements 1, 2, 3, 4 and 5 has the maximum frequency.
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 7th July 2024.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+"""
+### solution by pokgopun@gmail.com
+
+def maxFreq(ints: tuple):
+ ic = tuple((e, ints.count(e)) for e in set(ints))
+ mf = max(e[1] for e in ic)
+ return sum( mf for e in ic if e[1]==mf)
+
+import unittest
+
+class TestMaxFreq(unittest.TestCase):
+ def test(self):
+ for inpt,otpt in {
+ (1, 2, 2, 4, 1, 5): 4,
+ (1, 2, 3, 4, 5): 5,
+ }.items():
+ self.assertEqual(maxFreq(inpt),otpt)
+
+unittest.main()