aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wilson <steven1170@zoho.eu>2023-09-19 17:31:05 +0100
committerSteven Wilson <steven1170@zoho.eu>2023-09-19 17:31:05 +0100
commit467af61204a3f9c222c334f2af937cf62c03977e (patch)
treea45555e39d18ccff02bb1b92d015324bff1739fc
parentaee701524950403dce06a2a835452b79eacabce1 (diff)
downloadperlweeklychallenge-club-467af61204a3f9c222c334f2af937cf62c03977e.tar.gz
perlweeklychallenge-club-467af61204a3f9c222c334f2af937cf62c03977e.tar.bz2
perlweeklychallenge-club-467af61204a3f9c222c334f2af937cf62c03977e.zip
add solutions week 235 in python
-rw-r--r--challenge-235/steven-wilson/python/ch-01.py25
-rw-r--r--challenge-235/steven-wilson/python/ch-02.py32
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-235/steven-wilson/python/ch-01.py b/challenge-235/steven-wilson/python/ch-01.py
new file mode 100644
index 0000000000..4d5a26bae5
--- /dev/null
+++ b/challenge-235/steven-wilson/python/ch-01.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+
+def remove_one(elements):
+ """removing ONLY one integer makes it strictly increasing order
+ >>> remove_one( [0, 2, 9, 4, 6] )
+ True
+ >>> remove_one( [5, 1, 3, 2] )
+ False
+ >>> remove_one( [2, 2, 3] )
+ True
+ """
+ remove = 0
+ for i in range(len(elements) - 1):
+ if(elements[i] > elements[i+1]):
+ remove += 1
+ if remove == 2:
+ return False
+ return True
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()
diff --git a/challenge-235/steven-wilson/python/ch-02.py b/challenge-235/steven-wilson/python/ch-02.py
new file mode 100644
index 0000000000..9a5586206e
--- /dev/null
+++ b/challenge-235/steven-wilson/python/ch-02.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+
+def duplicate_zero(elements):
+ '''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
+ >>> duplicate_zero( [1, 0, 2, 3, 0, 4, 5, 0] )
+ [1, 0, 0, 2, 3, 0, 0, 4]
+ >>> duplicate_zero( [1, 2, 3] )
+ [1, 2, 3]
+ >>> duplicate_zero( [0, 3, 0, 4, 5] )
+ [0, 0, 3, 0, 0]
+ >>> duplicate_zero( [1, 2, 3, 0] )
+ [1, 2, 3, 0]
+ '''
+ duplicate_zeroes = []
+ elements_length = len(elements)
+ for i in range(elements_length):
+ if(elements[i] == 0):
+ duplicate_zeroes.extend([0,0])
+ else:
+ duplicate_zeroes.append(elements[i])
+ if len(duplicate_zeroes) >= elements_length:
+ break
+ return duplicate_zeroes[:elements_length]
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()