aboutsummaryrefslogtreecommitdiff
path: root/challenge-333/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-08-05 11:55:34 +0100
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-08-05 11:55:34 +0100
commit153f22e7dc6b1860d8561da89efeeefdfa83eab9 (patch)
tree01b2386dbff82575e1de7ec3c1a208295b046fd1 /challenge-333/eric-cheung/python
parent4869914836ceba6b2a3f0b2bd762cc5764d46dfb (diff)
downloadperlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.tar.gz
perlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.tar.bz2
perlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.zip
- Added solutions by Lukas Mai.
- Added solutions by E. Choroba.
Diffstat (limited to 'challenge-333/eric-cheung/python')
-rwxr-xr-xchallenge-333/eric-cheung/python/ch-1.py26
-rwxr-xr-xchallenge-333/eric-cheung/python/ch-2.py17
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-333/eric-cheung/python/ch-1.py b/challenge-333/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..59ee932762
--- /dev/null
+++ b/challenge-333/eric-cheung/python/ch-1.py
@@ -0,0 +1,26 @@
+
+import numpy as np
+
+def GetSlope (arrPt_1, arrPt_2):
+ dX1, dY1 = arrPt_1
+ dX2, dY2 = arrPt_2
+
+ if dX1 == dX2:
+ return np.nan
+
+ return (dY2 - dY1) / (dX2 - dX1)
+
+## arrList = [[2, 1], [2, 3], [2, 5]] ## Example 1
+## arrList = [[1, 4], [3, 4], [10, 4]] ## Example 2
+## arrList = [[0, 0], [1, 1], [2, 3]] ## Example 3
+## arrList = [[1, 1], [1, 1], [1, 1]] ## Example 4
+arrList = [[1000000, 1000000], [2000000, 2000000], [3000000, 3000000]] ## Example 5
+
+arrX = [arrLoop[0] for arrLoop in arrList]
+arrY = [arrLoop[1] for arrLoop in arrList]
+
+if len(set(arrX)) == 1 or len(set(arrY)) == 1:
+ print (True)
+else:
+ arrSlope = [GetSlope(arrList[nIndx - 1], arrList[nIndx]) for nIndx in range(1, len(arrList))]
+ print (len(set(arrSlope)) == 1)
diff --git a/challenge-333/eric-cheung/python/ch-2.py b/challenge-333/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..7e96b1df40
--- /dev/null
+++ b/challenge-333/eric-cheung/python/ch-2.py
@@ -0,0 +1,17 @@
+
+## arrInt = [1, 0, 2, 3, 0, 4, 5, 0] ## Example 1
+## arrInt = [1, 2, 3] ## Example 2
+## arrInt = [1, 2, 3, 0] ## Example 3
+## arrInt = [0, 0, 1, 2] ## Example 4
+arrInt = [1, 2, 0, 3, 4] ## Example 5
+
+arrOut = arrInt[:]
+
+arrZeroPos = [nPos for nPos, nElem in enumerate(arrInt) if nElem == 0]
+
+if len(arrZeroPos) == 0:
+ print (arrOut)
+else:
+ for nPos in arrZeroPos[::-1]:
+ arrOut.insert(nPos, 0)
+ print (arrOut[:len(arrInt)])