我不知道哪儿错了,求大神指导
import timet0 = time.time()
class point:
#初始化
def __init__(self, x, y):
self.x = x
self.y = y
self.available = []
self.value = 0
#初始化
#行
def rowNum(p, sudoku):
row = set(sudoku)
row.remove(0)
return row
#列
def colNum(p, sudoku):
col = []
hength = len(sudoku)
for i in range(p.x,, hength, 9):
col.append(sudoku)
col = set(col)
col.remove(0)
return col
def initPoint(sudoku):
pointlist = []
length = len(sudoku)
for i in range(length):
if (sudoku == 0):
p = point(i % 9, i//9)
for j in range(1, 10):
if (j not in rowNum(p, sudok and j not in colNum(p, sudok):
p.available.append(j)
pointlist.append(p)
return pointlist
def cheak(p, sudoku):
if (p.value == 0):
print('没有赋值给p')
return False
if (p.value not in rowNum(p, sudok and p.value not in colNum(p, sudok):
return True
else :
return False
def ti(p, sudoku):
availNum = p.available
for v in availNum:
p.value = v
if cheak(p, sudoku):
sudoku = p.value
if (len(pointlist) <= 0):
t1 = time.time()
useTime = (t1 - t0)
showSuduku(sudoku)
print('\nuse Time %f s' % (useTime))
exit()
p2 = pointlist.pop()
ti(p2, sudoku)
sudoku = 0
sudoku = 0
p2.value = 0
pointlist.append(p2)
else :
pass
def showSuduku(sudoku):
for i in range(9):
for j in range(9):
print('%d'%(sudoku))
print(' ')
if (__name__ == '__main__'):
sudoku =
pointlist = initPoint(sudoku)
showSuduku(sudoku)
print('''
''')
p = pointlist.pop()
print(p)
ti(p, sudoku)
sudoku = 0
sudoku = 0 这错了
keaimao 发表于 2022-10-17 19:35
sudoku = 0
sudoku = 0
这句话想表达什么意思,列表不能通过一个元组索引,得是一个整数,或者切片
页:
[1]