Ejemplo n.º 1
0
def solve_boards(file, guess, verbose):
	"""Solve each board in a text file."""
	if verbose:
		print('#', 'solved?', 'board', 'strategy', sep='\t')
	exclude = None if guess else [999]
	with open(file, 'r') as boards:
		for line in boards:
			line = line.strip()
			if not line or line.startswith('#'):
				continue
			board = Sudoku(line)
			n = board.num_solved()
			hardest = board.solve(exclude=exclude)
			try:
				board.verify()
			except:
				print('*** ERROR:', line)
				Sudoku(line).solve(exclude=exclude, verbose=True)
				break
			if verbose:
				print(board.num_solved() - n, 'TRUE' if board.solved() else 'FALSE',
					line, hardest, sep='\t')
Ejemplo n.º 2
0
def solve_board(board, guess, verbose):
	"""Solve a single board."""
	board = Sudoku(board)
	exclude = None if guess else [999]
	board.solve(exclude=exclude, verbose=verbose)
	board.verify()