aboutsummaryrefslogtreecommitdiff
path: root/challenge-204/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-02-14 08:03:38 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-02-14 08:03:38 +0000
commit6051a217ebf6f4804bf3015fc670971a489aecb0 (patch)
tree8bc53d3afbbaf85c73869423c339cef31b2e50b6 /challenge-204/eric-cheung/python
parent986b633b77c54044dc1679939a79cdb8d3164a4d (diff)
downloadperlweeklychallenge-club-6051a217ebf6f4804bf3015fc670971a489aecb0.tar.gz
perlweeklychallenge-club-6051a217ebf6f4804bf3015fc670971a489aecb0.tar.bz2
perlweeklychallenge-club-6051a217ebf6f4804bf3015fc670971a489aecb0.zip
- Added solutions by Mark Anderson.
- Added solutions by Lubos Kolouch. - Added solutions by Luca Ferrari. - Added solutions by Andrew Shitov. - Added solutions by W. Luis Mochan. - Added solutions by Thomas Kohler. - Added solutions by Matthew Neleigh. - Added solutions by E. Choroba. - Added solutions by Carlos Oliveira. - Added solutions by Robbie Hatley.
Diffstat (limited to 'challenge-204/eric-cheung/python')
-rwxr-xr-xchallenge-204/eric-cheung/python/ch-1.py33
-rwxr-xr-xchallenge-204/eric-cheung/python/ch-2.py32
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-204/eric-cheung/python/ch-1.py b/challenge-204/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..e4399c7369
--- /dev/null
+++ b/challenge-204/eric-cheung/python/ch-1.py
@@ -0,0 +1,33 @@
+
+def IsMonotone(arrInput):
+
+ bConstantArr = True
+ bMontoneInc = False
+
+ for nLastIndx in range(1, len(arrInput)):
+ if arrInput[nLastIndx - 1] == arrInput[nLastIndx]:
+ continue
+
+ bConstantArr = False
+
+ if arrInput[nLastIndx - 1] < arrInput[nLastIndx]:
+ bMontoneInc = True
+ break
+
+ break
+
+ if bConstantArr:
+ return "1"
+
+ for nLoopIndx in range(nLastIndx + 1, len(arrInput)):
+ if bMontoneInc and arrInput[nLoopIndx - 1] > arrInput[nLoopIndx] or not bMontoneInc and arrInput[nLoopIndx - 1] < arrInput[nLoopIndx]:
+ return "0"
+
+ return "1"
+
+
+## nInputArr = [1, 2, 2, 3] ## Example 1
+## nInputArr = [1, 3, 2] ## Example 2
+nInputArr = [6, 5, 5, 4] ## Example 3
+
+print (IsMonotone(nInputArr))
diff --git a/challenge-204/eric-cheung/python/ch-2.py b/challenge-204/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..5c6194a631
--- /dev/null
+++ b/challenge-204/eric-cheung/python/ch-2.py
@@ -0,0 +1,32 @@
+
+import numpy as np
+
+## Example 1
+## matrixInput = np.array([[1, 2], [3, 4]])
+## nMatrixReShapeRow = 1
+## nMatrixReShapeCol = 4
+
+## Example 2
+## matrixInput = np.array([[1, 2, 3], [4, 5, 6]])
+## nMatrixReShapeRow = 3
+## nMatrixReShapeCol = 2
+
+## Example 3
+matrixInput = np.array([1, 2])
+nMatrixReShapeRow = 3
+nMatrixReShapeCol = 2
+
+
+nMatrixRow = len(matrixInput)
+
+try:
+ nMatrixCol = len(matrixInput[0])
+except:
+ nMatrixCol = 0
+
+
+if nMatrixRow * nMatrixCol != nMatrixReShapeRow * nMatrixReShapeCol:
+ print ("0")
+else:
+ matrixOutput = matrixInput.reshape(nMatrixReShapeRow, nMatrixReShapeCol)
+ print (matrixOutput)