#说明新建sudoku文件夹下面由两个模块组成分别为主程序gui.py和解决模块solve.py 游戏运行主程序gui.py
#游戏玩法再生成的已知代码中的数组 9×9的题目 生成已知游戏,然后再图形界面中输入输入使用回车进行确认
# GUI.py
# RUN THIS FILE
import pygame
from solver import solve, valid
import time
pygame.font.init()
class Grid:
# To change the starting board change this
board = [
[0, 0, 0, 0, 2, 4, 0, 0, 3],
[3, 0, 0, 5, 0, 0, 0, 2, 0],
[0, 0, 4, 0, 0, 0, 1, 6, 0],
[0, 7, 6, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 6, 2, 8, 0, 0],
[0, 1, 0, 8, 0, 0, 6, 0, 7],
[0, 3, 0, 4, 0, 0, 5, 0, 8],
[0, 0, 7, 2, 0, 5, 0, 0, 0],
[0, 5, 0, 9, 8, 7, 0, 4, 2]
]
def __init__(self, rows, cols, width, height):
self.rows = rows
self.cols = cols
self.cubes = [[Cube(self.board[i][j], i, j, width, height) for j in range(cols)] for i in range(rows)]
self.width = width
self.height = height
self.model = None
self.selected = None
def update_model(self):
self.model = [[self.cubes[i][j].value for j in range(self.cols)] for i in range(self.rows)]
def place(self, val):
row, col = self.selected
if self.cubes[row][col].valeur == 0: Self.cubes[row][col].set(val) self.update_model() si valide(self.model, val, (row,col)) et résolve(self.model): retourner Vrai autre: self.cubes[row][col].set(0) self.cubes[row][col].set_temp(0)
self.update_model()
return False
def sketch(self, val):
row, col = self.selected
self.cubes[row][col].set_temp(val)
def draw(self, win):
# Draw Grid Lines
gap = self.width / 9
for i in range(self.rows+1):
if i % 3 == 0 and i != 0:
thick = 4
else:
thick = 1
pygame.draw.line(win, (0,0,0), (0, i*gap), (self.width, i*gap), thick)
pygame.draw.line(win, (0, 0, 0), (i * gap, 0), (i * gap, self.height), thick)
# Draw Cubes
for i in range(self.rows):
for j in range(self.cols):
self.cubes[i][j].draw(win)
def select(self, row, col):
# Reset all other
for i in range(self.rows):
for j in range(self.cols):
self.cubes[i][j].sélectionné = faux auto-cubes[row][col].selected = True
self.selected = (row, col)
def clear(self):
row, col = self.selected
if self.cubes[row][col].valeur == 0: Self.cubes[row][col].set_temp(0)
def click(self, pos):
« » »
:param: pos
:return: (row, col)
« » »
if pos[0] < largeur et pos[1] < hauteur de l ‘ auto-détecteur: écart = largeur de l ‘ auto-détecteur / 9 x = pos[0] // écart y = pos[1] // gap
return (int(y),int(x))
else:
return None
def is_finished(self):
for i in range(self.rows):
for j in range(self.cols):
if self.cubes[i][j].value == 0:
return False
return True
class Cube:
rows = 9
cols = 9
def __init__(self, value, row, col, width ,height):
self.value = value
self.temp = 0
self.row = row
self.col = col
self.width = width
self.height = height
self.selected = False
def draw(self, win):
fnt = pygame.font.SysFont(« comicsans », 40)
gap = self.width / 9
x = self.col * gap
y = self.row * gap
if self.temp != 0 and self.value == 0:
text = fnt.render(str(self.temp), 1, (128,128,128))
win.blit(text, (x+5, y+5))
elif not(self.value == 0):
text = fnt.render(str(self.value), 1, (0, 0, 0))
win.blit(text, (x + (gap/2 – text.get_width()/2), y + (gap/2 – text.get_height()/2)))
if self.selected:
pygame.draw.rect(win, (255,0,0), (x,y, gap ,gap), 3)
def set(self, val):
self.value = val
def set_temp(self, val):
self.temp = val
def redraw_window(win, board, time, strikes):
win.fill((255,255,255))
# Draw time
fnt = pygame.font.SysFont(« comicsans », 40)
text = fnt.render(« Time: » + format_time(time), 1, (0,0,0))
win.blit(text, (540 – 160, 560))
# Draw Strikes
text = fnt.render(« X » * strikes, 1, (255, 0, 0))
win.blit(text, (20, 560))
# Draw grid and board
board.draw(win)
def format_time(secs):
sec = secs%60
minute = secs//60
hour = minute//60
mat = » » + str(minute) + « : » + str(sec)
return mat
def main():
win = pygame.display.set_mode((540,600))
pygame.display.set_caption(« Sudoku »)
board = Grid(9, 9, 540, 540)
key = None
run = True
start = time.time()
strikes = 0
while run:
play_time = round(time.time() – start)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
key = 1
if event.key == pygame.K_2:
key = 2
if event.key == pygame.K_3:
key = 3
if event.key == pygame.K_4:
key = 4
if event.key == pygame.K_5:
key = 5
if event.key == pygame.K_6:
key = 6
if event.key == pygame.K_7:
key = 7
if event.key == pygame.K_8:
key = 8
if event.key == pygame.K_9:
key = 9
if event.key == pygame.K_DELETE:
board.clear()
key = None
if event.key == pygame.K_RETURN:
i, j = board.selected
if board.cubes[i][j].temp != 0: si board.place(board.cubes[i][j].temp): print(« Succès ») sinon: print(« Wrong ») frappe += 1 clé = Aucun si board.is_finish(): print(« Game over ») run = False si event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() cliqué = board.click(pos) si clique sur : board.select(cliced[0], cliqué[1]) clé = Aucun si board.sélectionné et clé != None: board.sketch(key) redraw_window(win, board, play_time, frappe) pygame.display.update() main() pygame.quit()
# solver.py
def solve(bo):
find = find_empty(bo)
if not find:
return True
else:
row, col = find
for i in range(1,10):
if valid(bo, i, (row, col)):
bo[row][col] = i si solid(bo): retourner True bo[row][col] = 0
return False
def valid(bo, num, pos):
# Check row
for i in range(len(bo[0])): en cas de[0]][i] == Nom et adresse ==[1] != i: retourner False # Vérifiez la colonne i dans range(len(bo)): si bo[i][dépose][1]] == num et pos[0] != i: retourner Faux # Cochez la case_x = pos[1] // 3 box_y = pos[0] // 3 pour i dans range(box_y*3, box_y*3 + 3): pour j dans range(box_x * 3, box_x*3 + 3): si bo[i][j] == num and (i,j) != pos:
return False
return True
def print_board(bo):
for i in range(len(bo)):
if i % 3 == 0 and i != 0:
print(« – – – – – – – – – – – – – « )
for j in range(len(bo[0])): si j % 3 == 0 et j != 0: print(« , fin) si j== 8: print(bo[i][j]) autres: print(str(bo)[i][j]) + » « , end= » »)
def find_empty(bo):
for i in range(len(bo)):
for j in range(len(bo[0])): si bo[i][j] == 0: retour (i, j) # ligne, col retour Aucun
附加解决独立程序(用于解决无法完成的sudoku)
import random
import sys
import numpy as np
sys.setrecursionlimit(100000) # 发现python默认的递归深度是很有限的
#(默认是1000),因此当递归深度超过999的
# 样子,就会引发这样的一个异常。
def get_next(m: »数独矩阵 », x: »空白格行数 », y: »空白格列数 »):
« » » 功能:获得下一个空白格在数独中的坐标。
« » »
for next_y in range(y+1, 9): # 下一个空白格和当前格在一行的情况
if m[x][next_y] = 0: retourner x, next_y pour next_x dans range(x+1, 9): # Suivante grille vide et courante non dans la ligne (0,9): si m[next_x][next_y] == 0:
return next_x, next_y
return -1, -1 # 若不存在下一个空白格,则返回 -1,-1
def value(m: »数独矩阵 », x: »空白格行数 », y: »空白格列数 »):
« » » 功能:返回符合 »每个横排和竖排以及
九宫格内无相同数字 »这个条件的有效值。
« » »
i, j = x//3, y//3
grid = [m[i*3+r][j*3+c] for r in range(3) for c in range(3)]
v = set([x for x in range(1,10)]) – ensemble(grid) – ensemble(m[x]) – \ set(list(zip(*m))[y])
return list(v)
def start_pos(m: »数独矩阵 »):
« » » 功能:返回第一个空白格的位置坐标 » » »
for x in range(9):
for y in range(9):
if m[x][y] == 0:
return x, y
return False, False # 若数独已完成,则返回 False, False
def try_sudoku(m: »数独矩阵 », x: »空白格行数 », y: »空白格列数 »):
« » » 功能:试着填写数独 « » »
for v in value(m, x, y):
m[x][y] = v next_x, next_y = get_text(m, x, y) si next_y = -1[x][y] = 0 # 在递归的过程中,如果数独没有解开,
# 则回溯到上一个空白格
def sudoku(m):
x, y = start_pos(m)
try_sudoku(m, x, y)
print(np.array(m))
Si ____nom_ = « __main_ »: m = [0, 0, 0, 2, 4, 0, 0, 3], [3, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 0], [0, 7, 6, 1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 8, 0, 0], [0, 10, 0, 0, 0], [0, 1, 0, 0, 0], [0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
附加程序2 用于生成sudoku的游戏题目数组
import random
import time
def pr(a):#用于输出方便阅读的结果
for i in range(9):
if i%3==0:
print(‘\t———\t\t———\t\t———‘)
for j in range(9):
if j%3==0:
print(‘|’,end=’\t’)
print(a[i][j],end=’\t’)
print(‘|’,end=’\n’)
print(‘\t———\t\t———\t\t———‘)
def diff(d):
print(‘数独难度:’,end= »)
if d==0:
print(‘极容易’)
if d==1:
print(‘容易’)
if d==2:
print(‘一般’)
if d==3:
print(‘困难’)
if d==4:
print(‘极困难’)
def con(a):#用于将数据转化为符合格式的序列
if len(a)==81:
a_con=[[],[],[],[],[],[],[],[],[]]
for i in range(9):
b=a[i*9:i*9+9]
for j in range(9):
a_con[i].annexe(int(b)[j]))
return a_con
return False
def examine_sudoku(sudoku):#检查是否符合数独规则
if len(sudoku)!=9:
return False
for i in range(9):
if len(sudoku[i])!=9 or sudoku[i]Nombre([])>0: retourner False pour j dans la plage (1,10): si sudoku[i]Nombre(j)>1:
return False
return True
def complete(a):#用于检测数独是否完成
for i in range(9):
for j in range(9):
if type(a[i][j])!=int or a[i][j]==0:
return False
return True
def copy(a):#复制数独的值,用于后期假设法运算失败,找回原来的值
d=[[], [], [], [], [], [], [], [], []]
for i in range(9):
for j in range(9):
if type(a[i][j])==int:
d[i]Annexe(a)[i][j]) type d’élif(a)[i][j])==Liste: d[i].append([]) pour k dans une[i][j]:d[i][j].append(k)
return d
def extract_b_c(a):#用9行表示的a,得到9列表示的b,及9宫表示的c,并对每个0所在的位置用[1,2,3,4,5,6,7,8,9]代替,作为笔记
b=[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]]
c=[[],[],[],[],[],[],[],[],[]]
for i in range(9):
for j in range(9):
if a[i][j]=0:a[i][j] = [1, 2, 3, 4, 5, 6, 7, 8, 9]b[j][i]=a[i][j]
s=ij_s(i,j) c[s]Annexe(a)[i][j])
return b,c
def ij_s(i,j):#用i和j求得宫所在的位置s
s=i//3*3+j//3
return s
def ij_t(i,j):#用i和j求得所在宫里的位置t
t=i%3*3+j%3
return t
def st_i(s,t):#用s和t求得原i的值
i=s//3*3+t//3
return i
def st_j(s, t):#用s和t求得原j的值
j=s%3*3+t%3
return j
def play_1(a,b,c,i,j,change):#将笔记中同行、同列及同宫的笔记里删除已知数字,并将唯一可能的格子变成已知数字
s=ij_s(i,j)
for num in range(1,10):
for k in range(9):
if type(a[i][k])==liste et num dans un[i] et num in a[i][k]: a[i][k].remove(num) change=Vrai si len(a[i][k]== Synchronisation, corrigée par le surgéliste[i][k][0]
a[i][k]=n b[k][i]=n
c[ij_s(i,k)][ij_t(i,k)]=n
change=True
if type(b[j][k])==liste et numéro en b[j] et num in b[j][k]:b[j][k].remove(num) change=True si len(b[j][k]== Synchronisation, corrigée par le surgéliste[j][k][0]
a[k][j]=n b[j][k]=n
c[ij_s(k,j)][ij_t(k,j)]=n
change=True
if type(c[s][k])==liste et nombre en c[s] et num in c[s][k]:c[s][k].remove(num) change=True si len(c[s][k]== Synchronisation, corrigée par le surgéliste[s][k][0]
[st_i(s,k)][st_j(s,k)]=n b[st_j(s,k)][st_i(s,k)]=n c[s][k]=n
change=True
return a,b,c,change
def play_2(a,b,c,i,j,change):#唯一候选数法
def num_abc():
num_a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
num_b = [1, 2, 3, 4, 5, 6, 7, 8, 9]
num_c = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for k in range(1,10):
if k in a[i]: num_a.remove(k) si k en b[j]: num_b.supprimer(k) si k en c[s]: num_c.remove(k) retourne num_a,num_b,num_c s=ij_s(i,j) num_a,num_b,num_c=num_abc() pour n in num_a: t=0 pour k dans l’intervalle(9): si type(a[i][k])==liste et n dans une[i][k]: t+=1 si t==1: pour k dans l’intervalle(9): si type(a[i][k]) == liste et n dans un[i][k]: a[i][k] = n b[k][i] = n c[ij_s(i, k)][ij_t(i, k)] = n num_a, num_b, num_c = num_abc() change=True pour n en num_b: t=0 pour k dans l’intervalle(9): si type(b[j][k])==liste et n in b[j][k]: t+=1 si t==1: pour k dans l’intervalle(9): si type(b[j][k])==liste et n in b[j][k]: a[k][j] = n b[j][k] = n c[ij_s(k, j)][ij_t(k, j)] = n num_a, num_b, num_c = num_abc() change=True pour n en num_c: t=0 pour k dans l’intervalle(9): si type(c[s][k])==liste et n en c[s][k]: t+=1 si t==1: pour k dans l’intervalle(9): si type(c[s][k])==liste et n en c[s][k]: a[st_i(s,k)][st_j(s,k)]=n b[st_j(s,k)][st_i(s,k)]=n c[s][k]=n
change=True
return a,b,c,change
def play_3(a,b,c,i,j,change):#链数删减法,专业用语是这样的,有2链数、3链数的,此方法扩展到n链数(帮助排除不可能项的)
list_a=[]
list_b=[]
list_c=[]
s=ij_s(i,j)
for k in range(9):
if type(a[i][k]) == liste: list_a.append(a[i][k]) pour k dans l’intervalle(9): si type(b[j][k]) == liste: list_b.append(b[j][k]) pour k dans l’intervalle(9): si type(c[s][k]) == liste: list_c.append(c[s][k]) pour k dans l’intervalle(3,len(list_a)+1): l=[] n=0 pour m dans list_a: si len(m)<k: pour p in m: si p n’est pas dans l: l.append(p) n+=1 si len(l)==n: pour m dans list_a: pour p in m: si p n’est pas dans l: pour q in l: si q dans m: m.remove(q) change=True for k in range(3,len(list_b)+1): l=[] n=0 pour m dans list_b: si len(m)<k: pour p in m: si p n’est pas dans l: l.append(p) n+=1 si len(l)==n: pour m dans list_b: pour p in m: si p n’est pas dans l: pour q in l: si q dans m: m.remove(q) change=True for k in range(3,len(list_c)+1): l=[] n=0 pour m dans list_c: si len(m)<k:
for p in m:
if p not in l:
l.append(p)
n+=1
if len(l)==n:
for m in list_c:
for p in m:
if p not in l:
for q in l:
if q in m:
m.remove(q)
change=True
return a,b,c,change
def play_4(a,b,c,change):#区块摒除法
for i in range(3):
m = [[], [], [], [], [], [], [], [], []]
for k in range(3):
for j in range(9):
if type(a[i * 3 + k][j]) == liste: pour n dans un[i * 3 + k][j]: si n n’est pas en m[k * 3 + j // 3]: m[k * 3 + j // 3].appendice(n) pour p dans l’intervalle(3): o = [] pour q dans l’intervalle(3): si m[p * 3 + q]Pour k in m[p * 3 + q]: si k n’est pas dans o: o.append(k) si o!=[]: pour s en o: t = 0 pour q dans l’intervalle(3): si s en m[p * 3 + q]: t += 1 si t == 1: pour q dans l’intervalle(3): si s en m[p * 3 + q]: si p == 0: l = [1, 2] elif p== 1: l = [0, 2] autre: l = [0, 1] pour k en l: pour j dans la plage(3): si type(a[i * 3 + k][q*3+j]) == liste et s dans une[i * 3 + k][q*3+j]:a[i * 3 + k][q*3+j].supprimer(s) changement(s) = Vrai pour i dans l’intervalle(3): m = [[], [], [], [], [], [], [], [], []] pour k dans l’intervalle(3): pour j dans l’intervalle(9): si type(b)[i * 3 + k][j]) == liste: pour n in b[i * 3 + k][j]: si n n’est pas en m[k * 3 + j // 3]: m[k * 3 + j // 3].appendice(n) pour p dans l’intervalle(3): o = [] pour q dans l’intervalle(3): si m[p * 3 + q]Pour k in m[p * 3 + q]: si k n’est pas dans o: o.append(k) si o!=[]: pour s en o: t = 0 pour q dans l’intervalle(3): si s en m[p * 3 + q]: t += 1 si t == 1: pour q dans l’intervalle(3): si s en m[p * 3 + q]: si p == 0: l = [1, 2] elif p== 1: l = [0, 2] autre: l = [0, 1] pour k en l: pour j dans la plage(3): si type(b[i * 3 + k][q*3+j]) == liste et s en b[i * 3 + k][q*3+j]:b[i * 3 + k][q*3+j].remove(s)
change = True
return a,b,c,change
def play_5(a,b,c,change,examine,a_copy):#假设法
if examine==True:
for l in range(2,10):
for i in range(9):
for j in range(9):
if type(a[i][j])==liste et len(a)[i][j])==l: a_copy=copy(a) n=a[i][j][random.randint(0,len(a)[i][j]_copie[i][j].supprimer(n) si len(a_copie[i][j])==1 : a_copie[i][j]=a_copie[i][j][0]
a[i][j]=n b[j][i]=n
c[ij_s(i,j)][ij_t(i,j)]=n
change=True
return a,b,c,change,examine,a_copy
if examine==False and examine_sudoku(a_copy)==True:
a=a_copy
b,c=extract_b_c(a)
change=True
examine=True
return a,b,c,change,examine,a_copy
examine=False
return a,b,c,change,examine,a_copy
def play_all(a,b,c,change,examine,a_copy,d):#进阶型运算,能初级方法解决就不用高级的方法,省时
for i in range(9):
for j in range(9):
a,b,c,change=play_1(a,b,c,i,j,change)
if change==False:
for i in range(9):
for j in range(9):
a,b,c,change=play_2(a,b,c,i,j,change)
if d<1 et changement ==True: si complet(a)==False: d=1 si changement==False: for i in range(9): for j in range(9): a,b,c,change=play_3(a,b,c,i,j,change) if d<2 et changement ==True: si complet(a)==False: d=2 si changement==False: a,b,c,change=play_4(a,b,c,change) si d<== Histoire ==False : d=3 si change==False : examin=review_sudoku(a) a,b,c,change,examine,a_copy=play_5(a,b,c,change,examiner,a_copy) si d<4 and change==True:
if complete(a)==False:
d=4
return a,b,c,change,examine,a_copy,d
def play_all_1(a,b,c,change,examine,a_copy):#进阶型运算,能初级方法解决就不用高级的方法,省时
for i in range(9):
for j in range(9):
a,b,c,change=play_1(a,b,c,i,j,change)
if change==False:
for i in range(9):
for j in range(9):
a,b,c,change=play_2(a,b,c,i,j,change)
if change==False:
for i in range(9):
for j in range(9):
a,b,c,change=play_3(a,b,c,i,j,change)
if change==False:
a,b,c,change=play_4(a,b,c,change)
return a,b,c,change,examine,a_copy
def complate_sudoku(a):#计算数独的主体
if examine_sudoku(a)==False:
return False
b,c = extract_b_c(a)
if examine_sudoku(b)==False:
return False
if examine_sudoku(c)==False:
return False
change = True#初始化change
examine=True#初始化examine
a_copy=[]#初始化a_copy
d=0
while change==True:
change=False
a,b,c,change,examine,a_copy,d=play_all(a,b,c,change,examine,a_copy,d)
examine=examine_sudoku(a)&examine_sudoku(b)&Si Complet(c) =False: retour Aucun, 4 retour a, d print (‘s generant Sudoku’) t=time.timeme() a=[,0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,<8: k=random.randint(0,len(l)-1) a[0][j]=l[k]
del l[k]
sinon:[0][j] =l[0]
l = [1, 2, 3, 4, 5, 6, 7, 8, 9][0][0]) l.supprimer(a)[0][1]) l.supprimer(a)[0][2]) pour i dans l’intervalle (1,9): si i==3: l = [1, 2, 3, 4, 5, 6, 7, 8, 9] l.supprimer(a[0][0]) l.supprimer(a)[1][0]) l.supprimer(a)[2][0]Si i<8: k=random.randint(0,len(l)-1) a[i][0]=l[k]
del l[k]
sinon:[i][0] =l[0]
l = [1, 2, 3, 4, 5, 6, 7, 8, 9][0][6]) l.supprimer(a)[0][7]) l.supprimer(a)[0][8]) pour i dans l’intervalle (1,9): si i==3: l = [1, 2, 3, 4, 5, 6, 7, 8, 9] l.supprimer(a[0][8]) l.supprimer(a)[1][8]) l.supprimer(a)[2][8]Si i<8: si i==7: si un[8][0] dans l: a[7][8]=a[8][0]
l.supprimer(a)[8][0]Ce billet fait partie de notre couverture spéciale Syrie Manifestations 2011.[8][8]=l[0]
k=random.randint(0,len(l)-1) tandis que l[k]=a[i][0]: k = aléatoire.randint(0, len(l) – 1) a[i][8]=l[k]
del l[k]
sinon:[i][8] =l[0]
l = [1, 2, 3, 4, 5, 6, 7, 8, 9][8][0]) l.supprimer(a)[8][8]b, c = initial_b_c(a) a_copy2=[] d, change, exusine, v), impression (‘Réponses universelles produites, ‘co ‘ , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ?? , ? , ?? , ?? , ?? , ?? , ?? , ?? , , , , , , , , 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] alors que x= =Vrai : changement = Vrai # originaliser examiner = Vrai>1: k=random.randint(0,len(l)-1) autre: k=0 x=False p=l[k]/ 9 q=l[k]%9 del l[k]
si co[p][q]==0: continuer[p][q]=Cop=copy(co)cop_b, cop_c =extract_b_c(cop) tout en changeant = Vrai: changement, cap_b, pop_c, changement, exportation, a_co=play_all_1 (cop, cop_b, cap_c, changement, changement, changement, changement, changement), changement, exemple =Play_all_1 (cop, cop_b, copie, export, si co_co) =True: a = copy(co) autre: ti= 0: impression (la difficulté générale a été générée, le problème est aiguisé …) = 1 pour i dans l’intervalle (9): pour j dans la taille(copy(co)[i][j])==Liste et len(cop)[i][j])==2: a_copy=copy(cop) n=cop[i][j][0]
a_copie[i][j]=a_copie[i][j][1]
a_copy_b, a_copy_c = copie d’extraits[i][j]=n cop_b[j][i]= n cop_c[ij_s(i,j)]}n change=True while changeing =True: change, a_cop_b, cop_c, change, export, aco, d=play_all (cop, pop_b, cap_c, change, change, alternative, world change = True: change = Faux a_copie, a_copy_capy, a_copy_b, a_compete_c/(commate), emine, an_tope=Cope=a Si cop= =com ou cop=com: a = copy(co) print (est tout généré, ‘,time.time()-(t) pr(a)=time.time() a,d=compate
未经允许不得转载:萌萌Apprentissage » Utilisez python pour générer 2 programmes séparés pour le jeu sidoku, créer le profil sidoku et résoudre le programme sodoku
Python lote pour extraire des images de moteurs de recherche
Le mot de Python grimpant à 100 degrés.
PythonTaiichi Taipei Intelligence artificielle Traitement graphique de Tensoflow
Sélénium avec navigateur Tor en utilisant Python
Je vais t'en chercher un nouveau, Shell.cloud.google en ligne.
exécuter crontab avec python sélénium tor navigateur affichage dans linux
Environnement Lineux Utilisez python pour appeler la page Web du navigateur ter aléatoire