aboutsummaryrefslogtreecommitdiff
path: root/challenge-197/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-12-28 09:53:11 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-12-28 09:53:11 +0000
commitef1b6e72f5f8b7b06df4f7f955522b0eb7f554fd (patch)
tree95dda08c8d7524fdc19557a26af65a9c0cf9e02e /challenge-197/eric-cheung/python
parentcd95529589f05076aa13fa21b8cc89a87263b90d (diff)
downloadperlweeklychallenge-club-ef1b6e72f5f8b7b06df4f7f955522b0eb7f554fd.tar.gz
perlweeklychallenge-club-ef1b6e72f5f8b7b06df4f7f955522b0eb7f554fd.tar.bz2
perlweeklychallenge-club-ef1b6e72f5f8b7b06df4f7f955522b0eb7f554fd.zip
- Added solutions by Niels van Dijke.
- Added solutions by Flavio Poletti. - Added solutions by Ali Moradi. - Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-197/eric-cheung/python')
-rwxr-xr-xchallenge-197/eric-cheung/python/ch-1.py10
-rwxr-xr-xchallenge-197/eric-cheung/python/ch-2.py23
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-197/eric-cheung/python/ch-1.py b/challenge-197/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..b84bff5774
--- /dev/null
+++ b/challenge-197/eric-cheung/python/ch-1.py
@@ -0,0 +1,10 @@
+
+import numpy as np
+
+## arrInputList = np.array([1, 0, 3, 0, 0, 5]) ## Example 1
+## arrInputList = np.array([1, 6, 4]) ## Example 2
+arrInputList = np.array([0, 1, 0, 2, 0]) ## Example 3
+
+arrOutputList = np.append(arrInputList[arrInputList != 0], arrInputList[arrInputList == 0])
+
+print (arrOutputList)
diff --git a/challenge-197/eric-cheung/python/ch-2.py b/challenge-197/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..f95f735238
--- /dev/null
+++ b/challenge-197/eric-cheung/python/ch-2.py
@@ -0,0 +1,23 @@
+
+## Remarks
+## https://zhenyu0519.github.io/2020/07/12/lc280/
+
+def wiggleSort(arrSubInput):
+
+ bGtr = False
+ arrSubOutput = arrSubInput
+
+ for nLoop in range(len(arrSubOutput) - 1):
+ if bGtr and arrSubOutput[nLoop] <= arrSubOutput[nLoop + 1] or not bGtr and arrSubOutput[nLoop] >= arrSubOutput[nLoop + 1]:
+ arrSubOutput[nLoop], arrSubOutput[nLoop + 1] = arrSubOutput[nLoop + 1], arrSubOutput[nLoop]
+
+ bGtr = not bGtr
+
+ return arrSubOutput
+
+
+## arrInputList = [1, 5, 1, 1, 6, 4] ## Example 1
+## arrInputList = [1, 3, 2, 2, 3, 1] ## Example 2
+arrInputList = [1, 5, 2, 3, 4, 6] ## Example
+
+print (wiggleSort(arrInputList))