目标是在 Python 中创建一个 9x9 数独矩阵。
所以我走到了这一步。但我似乎无法让程序使内部的临时箱正确。
def sudoku(size):
import random as rn
mydict = {}
n = 0
while len(mydict) < 9:
n += 1
x = range(1, size+1)
testlist = rn.sample(x, len(x))
isgood = True
for dictid,savedlist in mydict.items():
if isgood == False:
break
for v in savedlist:
if testlist[savedlist.index(v)] == v:
isgood = False
break
if isgood == True:
#print 'success', testlist
mydict[len(mydict)] = testlist
return mydict, n
return_dict, total_tries = sudoku(9)
for n,v in return_dict.items():
print n,v …
Run Code Online (Sandbox Code Playgroud) 此外,Snowflake 如何“柱状化”其所有数据?
我读过的任何内容都没有很好地解释它