aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-09-20 14:36:49 +0100
committerGitHub <noreply@github.com>2023-09-20 14:36:49 +0100
commitebffa81f5e92a5d54b12eb33387fa0ce3dcd73b9 (patch)
treefeba4a6b22f33ba28a265d09b63fe04123db3c82
parent37f4ceeacbc434aa32cef291ffe67f95391963e8 (diff)
parent6da71e0cb35dca7e75deb5d2fbfc3eb0a84f72f0 (diff)
downloadperlweeklychallenge-club-ebffa81f5e92a5d54b12eb33387fa0ce3dcd73b9.tar.gz
perlweeklychallenge-club-ebffa81f5e92a5d54b12eb33387fa0ce3dcd73b9.tar.bz2
perlweeklychallenge-club-ebffa81f5e92a5d54b12eb33387fa0ce3dcd73b9.zip
Merge pull request #8734 from pokgopun/pwc235
pwc235 solution
-rw-r--r--challenge-235/pokgopun/go/ch-1.go80
-rw-r--r--challenge-235/pokgopun/go/ch-2.go70
-rw-r--r--challenge-235/pokgopun/python/ch-1.py56
-rw-r--r--challenge-235/pokgopun/python/ch-2.py57
4 files changed, 263 insertions, 0 deletions
diff --git a/challenge-235/pokgopun/go/ch-1.go b/challenge-235/pokgopun/go/ch-1.go
new file mode 100644
index 0000000000..0eb71efb8d
--- /dev/null
+++ b/challenge-235/pokgopun/go/ch-1.go
@@ -0,0 +1,80 @@
+//# 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
+
+package main
+
+import "fmt"
+
+func main() {
+ for _, data := range []struct {
+ input []int
+ output bool
+ }{
+ {[]int{0, 2, 9, 4, 6}, true},
+ {[]int{5, 1, 3, 2}, false},
+ {[]int{2, 2, 3}, true},
+ } {
+ fmt.Println(isRmoSorted(data.input) == data.output)
+ }
+}
+
+func isRmoSorted(s []int) bool {
+ l := len(s)
+ var (
+ first, isSorted bool
+ v int
+ )
+ for i := 0; i < l; i++ {
+ isSorted = true
+ first = true
+ for j := 0; j < l; j++ {
+ if j == i {
+ continue
+ }
+ if first == true {
+ first = false
+ } else {
+ if s[v] > s[j] {
+ isSorted = false
+ break
+ }
+ }
+ v = j
+ }
+ if isSorted == true {
+ return true
+ }
+ }
+ return false
+}
diff --git a/challenge-235/pokgopun/go/ch-2.go b/challenge-235/pokgopun/go/ch-2.go
new file mode 100644
index 0000000000..5da191a3c7
--- /dev/null
+++ b/challenge-235/pokgopun/go/ch-2.go
@@ -0,0 +1,70 @@
+//# 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
+
+package main
+
+import (
+ "fmt"
+ "slices"
+)
+
+func main() {
+ for _, data := range []struct {
+ input, output []int
+ }{
+ {[]int{1, 0, 2, 3, 0, 4, 5, 0}, []int{1, 0, 0, 2, 3, 0, 0, 4}},
+ {[]int{1, 2, 3}, []int{1, 2, 3}},
+ {[]int{0, 3, 0, 4, 5}, []int{0, 0, 3, 0, 0}},
+ } {
+ fmt.Println(slices.Equal(dupZero(data.input), data.output))
+ }
+}
+
+func dupZero(s []int) []int {
+ l := len(s)
+ i := 0
+ for i < l {
+ if s[i] == 0 {
+ copy(s[i+2:], s[i+1:])
+ s[i+1] = 0
+ i++
+ }
+ i++
+ }
+ return s
+}
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)
+
+