import time
s_time = time.time()
grid = []
for i in range(7):
temp = []
for j in range(7):
temp.append(int(input()))
grid.append(temp)
color = []
for i in range(7):
temp = []
for j in range(7):
temp.append(input())
color.append(temp)
def print_board(board):
for i in range(7):
for j in range(7):
print(board[i][j],end=" ")
print()
def get_pos(board):
for i in range(7):
for j in range(7):
if board[i][j] == 0:
return i,j
return None
def valid_board(board,row,col):
for i in range(7):
if (row,i)!=(row,col) and board[row][i]==board[row][col]:
return False
else:
continue
for i in range(7):
if (i,col)!=(row,col) and board[i][col]==board[row][col]:
return False
else:
continue
for i in range(7):
for j in range(7):
if color[row][col]!=color[i][j]:
continue
else:
if (i,j)!=(row,col) and board[i][j]==board[row][col]:
return False
else:
continue
return True
def solve():
global grid
pos = get_pos(grid)
if not pos:
return True
row,col = pos[0],pos[1]
for i in range(1,8):
grid[row][col] = i
if valid_board(grid,row,col):
if solve():
return True
grid[row][col] = 0
return False
print("Input sudoku board: ")
print()
print_board(grid)
print()
print("Input sudoku board color: ")
print()
print_board(color)
print("---------------------------------")
print(solve())
print("---------------------------------")
print("Output sudoku: ")
print()
print_board(grid)
print()
print("Executuin time : ",time.time()-s_time,'s')