aboutsummaryrefslogtreecommitdiff
path: root/challenge-266/eric-cheung/python/ch-2.py
blob: 0c74ebfbf3d3a50df094ce0653dcbb9763455eb0 (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
27
28
29
30
31
32
33
34
def IsXMatrix (arrInputMatrix):

    nLen = len(arrInputMatrix)

    ## Check
    for nRowIndx in range(nLen):

        nColIndx_01 = nRowIndx
        nColIndx_02 = nLen - nRowIndx - 1

        ## 1st
        if arrInputMatrix[nRowIndx][nColIndx_01] == 0:
            return False

        ## 2nd
        if arrInputMatrix[nRowIndx][nColIndx_02] == 0:
            return False

        ## 3rd
        for nColIndx in range(nLen):
            if nColIndx in [nColIndx_01, nColIndx_02]:
                continue

            if arrInputMatrix[nRowIndx][nColIndx] != 0:
                return False

    return True

## arrMatrix = [[1, 0, 0, 2], [0, 3, 4, 0], [0, 5, 6, 0], [7, 0, 0, 1]]  ## Example 1
## arrMatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]  ## Example 2
arrMatrix = [[1, 0, 2], [0, 3, 0], [4, 0, 5]]  ## Example 3

print (IsXMatrix (arrMatrix))