aboutsummaryrefslogtreecommitdiff
path: root/challenge-235/pokgopun/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-235/pokgopun/python/ch-2.py')
-rw-r--r--challenge-235/pokgopun/python/ch-2.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/challenge-235/pokgopun/python/ch-2.py b/challenge-235/pokgopun/python/ch-2.py
new file mode 100644
index 0000000000..6aece949e1
--- /dev/null
+++ b/challenge-235/pokgopun/python/ch-2.py
@@ -0,0 +1,57 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-235/
+"""
+
+Task 2: Duplicate Zeros
+
+Submitted by: [45]Mohammad S Anwar
+ __________________________________________________________________
+
+ You are given an array of integers.
+
+ Write a script to duplicate each occurrence of ZERO in the given array
+ and shift the remaining to the right but make sure the size of array
+ remain the same.
+
+Example 1
+
+Input: @ints = (1, 0, 2, 3, 0, 4, 5, 0)
+Ouput: (1, 0, 0, 2, 3, 0, 0, 4)
+
+Example 2
+
+Input: @ints = (1, 2, 3)
+Ouput: (1, 2, 3)
+
+Example 3
+
+Input: @ints = (0, 3, 0, 4, 5)
+Ouput: (0, 0, 3, 0, 0)
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 24th September
+ 2023.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+"""
+### solution by pokgopun@gmail.com
+
+def dupZero(tup):
+ lst = list(tup)
+ l = len(lst)
+ i = 0
+ while i < l:
+ if lst[i]==0:
+ lst.insert(i,0)
+ i += 1
+ i += 1
+ return tuple(lst[:l])
+
+for inpt,otpt in {
+ (1, 0, 2, 3, 0, 4, 5, 0): (1, 0, 0, 2, 3, 0, 0, 4),
+ (1, 2, 3): (1, 2, 3),
+ (0, 3, 0, 4, 5): (0, 0, 3, 0, 0),
+ }.items():
+ print(dupZero(inpt)==otpt)
+
+