From 368f5829f6692f35ea4e0baa698d6512b7eb274b Mon Sep 17 00:00:00 2001 From: Michael Firkins Date: Tue, 19 Sep 2023 05:19:12 +1000 Subject: pwc235 solution in python --- challenge-235/pokgopun/python/ch-1.py | 56 ++++++++++++++++++++++++++++++++++ challenge-235/pokgopun/python/ch-2.py | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 challenge-235/pokgopun/python/ch-1.py create mode 100644 challenge-235/pokgopun/python/ch-2.py diff --git a/challenge-235/pokgopun/python/ch-1.py b/challenge-235/pokgopun/python/ch-1.py new file mode 100644 index 0000000000..6a0ff781d2 --- /dev/null +++ b/challenge-235/pokgopun/python/ch-1.py @@ -0,0 +1,56 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-235/ +""" + +Task 1: Remove One + +Submitted by: [44]Mohammad S Anwar + __________________________________________________________________ + + You are given an array of integers. + + Write a script to find out if removing ONLY one integer makes it + strictly increasing order. + +Example 1 + +Input: @ints = (0, 2, 9, 4, 6) +Output: true + +Removing ONLY 9 in the given array makes it strictly increasing order. + +Example 2 + +Input: @ints = (5, 1, 3, 2) +Output: false + +Example 3 + +Input: @ints = (2, 2, 3) +Output: true + +Task 2: Duplicate Zeros +""" +### solution by pokgopun@gmail.com + +def isRmoSorted(lst): + l = len(lst) + for i in range(l): + v = None + isSorted = True + for j in range(l): + if j == i: continue + if v != None: + #print(v,j) + if lst[v] > lst[j]: + isSorted = False + break + v = j + if isSorted == True: return True + return False + +for inpt,otpt in { + (0, 2, 9, 4, 6): True, + (5, 1, 3, 2): False, + (2, 2, 3): True, + }.items(): + print(isRmoSorted(inpt)==otpt) 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) + + -- cgit