aboutsummaryrefslogtreecommitdiff
path: root/challenge-257/eric-cheung/python/ch-2.py
blob: 3b13af9e919d940a6f395bf158d8df9ee7124e5c (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
35
## arrMatrix = [[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3]]
## arrMatrix = [[1, 1, 0], [0, 1, 0], [0, 0, 0]]  ## Example 1
## arrMatrix = [[0, 1, -2, 0, 1], [0, 0, 0, 1, 3], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]  ## Example 2
## arrMatrix = [[1, 0, 0, 4], [0, 1, 0, 7], [0, 0, 1, -1]]  ## Example 3
## arrMatrix = [[0, 1, -2, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 1, 3], [0, 0, 0, 0, 0]]  ## Example 4
## arrMatrix = [[0, 1, 0], [1, 0, 0], [0, 0, 0]]  ## Example 5
arrMatrix = [[4, 0, 0, 0], [0, 1, 0, 7], [0, 0, 1, -1]]  ## Example 6

t_arrMatrix = [arrLoop for arrLoop in zip(*arrMatrix)]

## print (t_arrMatrix)

arrLead_1_Pos = [-1 if len([1 for arrColLoop in arrRowLoop if arrColLoop == 1]) == 0 else min([nIndx for nIndx, arrColLoop in enumerate(arrRowLoop) if arrColLoop == 1]) for arrRowLoop in arrMatrix]

## print (arrLead_1_Pos)

arrLead_1_Positive = [nLoop for nLoop in arrLead_1_Pos if nLoop >= 0]
arrLead_1_Pos_Positive = [nIndx for nIndx, nLoop in enumerate(arrLead_1_Pos) if nLoop >= 0]
arrLead_1_Pos_Negative = [nIndx for nIndx, nLoop in enumerate(arrLead_1_Pos) if nLoop < 0]

## print (arrLead_1_Positive)
## print (arrLead_1_Pos_Positive)
## print (arrLead_1_Pos_Negative)

bResult = (sorted(arrLead_1_Positive) == arrLead_1_Positive)
if bResult and len(arrLead_1_Pos_Negative) > 0:
    bResult = (arrLead_1_Pos_Positive[-1] < arrLead_1_Pos_Negative[0])
if bResult:
    for arrLoop in t_arrMatrix[:-1]:
        if sum([0 if rLoop == 0 else 1 for rLoop in arrLoop]) > 1:
            bResult = False
            break

print (1 if bResult else 0)