-
Notifications
You must be signed in to change notification settings - Fork 2
/
results_check.py
114 lines (87 loc) · 4.66 KB
/
results_check.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def check(matrix,n,last_input,data_dict):
if data_dict[last_input]:
for cordinates in data_dict[last_input]:
temp=check_result(matrix,n,cordinates)
if temp:
return temp
return 0
def check_result(matrix,n,cordinates):
x=cordinates[0]#getting x
y=cordinates[1]#getting y
#the most tricky part is the cordinate 0 0 because it has three chances to complete the loop
if x==0 and y==0:
temp=check_diagonally(matrix,n)
if(temp):
return temp
temp=check_col(matrix,y,n)
if(temp):
return temp
temp=check_row(matrix,x,n)
if temp:
return temp
else:
return 0
elif x==0:
temp= check_col(matrix,y,n)
if temp:
return temp
elif y==0:
temp=check_row(matrix,x,n)
if temp:
return temp
def check_diagonally(matrix,n):
count=1
for i in range(n-1):
if matrix[i][i]==matrix[i+1][i+1]:
count+=1
else:
break
if count==n:
temp=[1,n*n]
return temp
else:
return 0
def check_col(matrix,y,n):
count=1
for i in range(n-1):
if matrix[i][y]==matrix[i+1][y]:
count+=1
else:
break
if count==n:
temp=[y+1,(n-1)*n+y+1]
return temp
if y==n-1:
count=1
for i in range(n-1):
if matrix[i][y-i]==matrix[i+1][y-i-1]:
count+=1
else:
break
if count==n:
temp=[y+1,n*(n-1)+1]
return temp
else:
return 0
def check_row(matrix,x,n):
count=1
for i in range(n-1):
if matrix[x][i]==matrix[x][i+1]:
count+=1
else:
break
if count==n:
temp=[x*n+1,(x+1)*n]
return [x*n+1,(x+1)*n]
elif x==n-1:
count=1
for i in range(n-1):
if matrix[x-i][i]==matrix[x-i-1][i+1]:
count+=1
else:
break
if count==n:
temp=[x*n+1,n]
return temp
else:
return 0