diff options
Diffstat (limited to 'challenge-333/eric-cheung/python')
| -rwxr-xr-x | challenge-333/eric-cheung/python/ch-1.py | 26 | ||||
| -rwxr-xr-x | challenge-333/eric-cheung/python/ch-2.py | 17 |
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)])
|
