aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-326/pokgopun/python/ch-1.py58
-rw-r--r--challenge-326/pokgopun/python/ch-2.py62
2 files changed, 120 insertions, 0 deletions
diff --git a/challenge-326/pokgopun/python/ch-1.py b/challenge-326/pokgopun/python/ch-1.py
new file mode 100644
index 0000000000..50d226eae0
--- /dev/null
+++ b/challenge-326/pokgopun/python/ch-1.py
@@ -0,0 +1,58 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-326/
+"""
+
+Task 1: Day of the Year
+
+Submitted by: [43]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given a date in the format YYYY-MM-DD.
+
+ Write a script to find day number of the year that the given date
+ represent.
+
+Example 1
+
+Input: $date = '2025-02-02'
+Output: 33
+
+The 2nd Feb, 2025 is the 33rd day of the year.
+
+Example 2
+
+Input: $date = '2025-04-10'
+Output: 100
+
+Example 3
+
+Input: $date = '2025-09-07'
+Output: 250
+
+Task 2: Decompressed List
+"""
+### solution by pokgopun@gmail.com
+
+def doy(date: str) -> int:
+ y, m, d = (int(e) for e in date.split('-'))
+ return d + 30*(m-1) + sum((e-7*(e//8))%2 for e in range(1,m)) - (m>2)*(2 - ilp(y))
+
+def ilp(y: int) -> bool:
+ if y % 4 == 0:
+ if y % 100 == 0:
+ return y % 400 == 0
+ else:
+ return True
+ return False
+
+import unittest
+
+class TestDoy(unittest.TestCase):
+ def test(self):
+ for inpt, otpt in {
+ '2025-02-02': 33,
+ '2025-04-10': 100,
+ '2025-09-07': 250,
+ }.items():
+ self.assertEqual(doy(inpt),otpt)
+
+unittest.main()
diff --git a/challenge-326/pokgopun/python/ch-2.py b/challenge-326/pokgopun/python/ch-2.py
new file mode 100644
index 0000000000..ff06bd3c5d
--- /dev/null
+++ b/challenge-326/pokgopun/python/ch-2.py
@@ -0,0 +1,62 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-326/
+"""
+
+Task 2: Decompressed List
+
+Submitted by: [44]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given an array of positive integers having even elements.
+
+ Write a script to to return the decompress list. To decompress, pick
+ adjacent pair (i, j) and replace it with j, i times.
+
+Example 1
+
+Input: @ints = (1, 3, 2, 4)
+Output: (3, 4, 4)
+
+Pair 1: (1, 3) => 3 one time => (3)
+Pair 2: (2, 4) => 4 two times => (4, 4)
+
+Example 2
+
+Input: @ints = (1, 1, 2, 2)
+Output: (1, 2, 2)
+
+Pair 1: (1, 1) => 1 one time => (1)
+Pair 2: (2, 2) => 2 two times => (2, 2)
+
+Example 3
+
+Input: @ints = (3, 1, 3, 2)
+Output: (1, 1, 1, 2, 2, 2)
+
+Pair 1: (3, 1) => 1 three times => (1, 1, 1)
+Pair 2: (3, 2) => 2 three times => (2, 2, 2)
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 22nd June 2025.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+"""
+### solution by pokgopun@gmail.com
+
+from itertools import repeat, chain
+
+def dl(ints: tuple[int]) -> tuple[int]:
+ return tuple(chain.from_iterable(repeat(ints[2*i+1],ints[2*i]) for i in range(len(ints)//2)))
+
+import unittest
+
+class TestDl(unittest.TestCase):
+ def test(self):
+ for inpt, otpt in {
+ (1, 3, 2, 4): (3, 4, 4),
+ (1, 1, 2, 2): (1, 2, 2),
+ (3, 1, 3, 2): (1, 1, 1, 2, 2, 2),
+ }.items():
+ self.assertEqual(dl(inpt),otpt)
+
+unittest.main()