Import NumPy as NP
Import Sys
Sys.setrecursionlimit (#例如这里设置为一百万)
def get1 (n):
If n<3:
return 0
If n<6:
Return 3
Return 6
def get2 (n):
If n<3:
Return 3
If n<6:
Return 6
Return 9
def get3 (arr,i,j):
A1=list (Arr[i,:])
A2=list (Arr[:,j])
A3=list (Arr[get1 (i): Get2 (i), Get1 (j): Get2 (j)].reshape (1,-1) [0])
A=set (A1+A2+A3)
Return b-a
def SD (ARR,DEP):
Count[0]+=1
If Dep==len (l):
Result.append (arr)
Else
X,Y=L[DEP]
Lac=get3 (Arr,x,y)
If Len (LAC) >0 and Len (result) ==0:
For I in Lac:
Ac=arr.copy ()
Ac[x,y]=i
SD (AC,DEP+1)
array= [[5,3,0,0,7,0,0,0,0],
[6,0,0,1,9,5,0,0,0],
[0,9,8,0,0,0,0,6,0],
[8,0,0,0,6,0,0,0,3],
[4,0,0,8,0,3,0,0,1],
[7,0,0,0,2,0,0,0,6],
[0,6,0,0,0,0,2,8,0],
[0,0,0,4,1,9,0,0,5],
[0,0,0,0,8,0,0,7,9]]
Array=np.array (Array)
B,L,OLD,RESULT,COUNT={1,2,3,4,5,6,7,8,9},[],[],[],[0]
For I in Range (0,9):
For j in Range (0,9):
If array[i,j]==0:
L.append ((I,J))
SD (array,0)
Print (Result)
Leetcode python 037 Solving Sudoku