This repository has been archived by the owner on Jun 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_terminate.py
94 lines (88 loc) · 2.5 KB
/
is_terminate.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
import sys
from object.Matrix import *
import numpy as np
def check_row_right(matrix,row,column,size):
global flag,max
val = matrix[row][column]
while(column < size):
if matrix[row][column] != val:
if matrix[row][column] == 0 and (column - 1) >= 0:
if matrix[row][column - 1] == max:
flag = 1
return (True)
val += 1
column += 1
return (False)
def check_row_left(matrix,row,column,size):
global flag,max,sz
val = matrix[row][column]
while(column >= size):
if matrix[row][column] != val:
if matrix[row][column] == 0 and (column + 1) < sz:
if matrix[row][column + 1] == max:
flag = 1
return (True)
val += 1
column -= 1
return (False)
def check_column_down(matrix,row,column,size):
global flag,max
val = matrix[row][column]
while(row < size):
if matrix[row][column] != val:
if matrix[row][column] == 0 and (row - 1) >= 0:
if matrix[row - 1][column] == max:
flag = 1
return (True)
val += 1
row += 1
return (False)
def check_column_up(matrix,row,column,size):
global flag,max,sz
val = matrix[row][column]
while(row > size):
if matrix[row][column] != val:
if matrix[row][column] == 0 and (row + 1) < sz:
if matrix[row + 1][column] == max:
flag = 1
return (True)
val += 1
row -= 1
return (False)
def check_solve(matrix):
global flag,max,sz
flag = 0
count = 1
sz = size = len(matrix)
max = size * size - 1
row = 0
column = 0
i = 1
j = 0
while (True):
if check_row_right(matrix,row,column,size - j):
if flag:
print "one"
return (True)
return (False)
if check_column_down(matrix,row,size - i,size - j):
if flag:
print "two"
return (True)
return (False)
if check_row_left(matrix,size - i,size - i,j):
if flag:
print "three"
return (True)
return (False)
if check_column_up(matrix,size - i,column,j):
if flag:
print "four"
return (True)
return (False)
row += 1
column = column + j
j += 1
i += 1
return (True)