print
        for j in xrange(9):
            print sudoku[i][j],
    print "\n"


REPS = 50
EMPTY_TILES = 25

if __name__ == "__main__":
    for _ in xrange(REPS):
        empty_tiles = EMPTY_TILES
        tiles = [x for x in xrange(81)]
        random.shuffle(tiles)
        c = 0
        count, sudoku = fill_partial_sudoku(generate_partial_sudoku())
        original = [row[:] for row in sudoku]
        while empty_tiles > 0:
            tile = tiles.pop()
            i, j = get_sudoku_position(tile)
            value = sudoku[i][j]
            sudoku[i][j] = "x"
            count = 0

            for _ in sudoku_solver(sudoku):
                count += 1

            if count != 1:
                sudoku[i][j] = value
                tiles.append(tile)
                random.shuffle(tiles)
Exemple #2
0
        g = sudoku_solver(empty_board)
        for _ in xrange(generate):
            board = g.next()
            sudoku = generate_sudoku_table(board, empty_tiles)
            print_sudokus(board, sudoku, print_answer_only)
        sys.exit(0)

    # Generate a full board
    for i in xrange(generate):
        if input_file:
            board, l = read_sudoku(input_file)
            if l == 0:
                if generate - i != 1:
                    sys.stderr.write("Expecting " + str(generate - i) + " more boards from file " + args.input_file + "\n")
                else:
                    sys.stderr.write("Expecting 1 more board from file " + args.input_file + "\n")
                sys.exit(0)
            lines += l
            if board == None:
                sys.stderr.write("Error reading the board from file: " + args.input_file + " Line: " + str(lines) + "\n")
                sys.exit(0)
            input_file.readline()
        else:
            count, board = fill_partial_sudoku(generate_partial_sudoku(seed))
        sudoku = generate_sudoku_table(board, empty_tiles)

        print_sudokus(board, sudoku, print_answer_only)



def generate_sudoku_board():
    return fill_partial_sudoku(generate_partial_sudoku())