aboutsummaryrefslogtreecommitdiff
path: root/challenge-333/eric-cheung/python/ch-1.py
blob: 59ee9327628d7c47d1236561ecdd7c45bd30c320 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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)