Esempio n. 1
0
int main() {
    Solution s;
    {
        auto board = 
            buildBoard(vector<string>{
            "53..7....",
                "6..195...",
                ".98....6.",

                "8...6...3",
                "4..8.3..1",
                "7...2...6",

                ".6....28.",
                "...419..5",
                "....8..79",
        });
        s.solveSudoku(board);
        printBoard(board);
    }
    {
        auto board =
            buildBoard(vector<string>{
                "..9748...", 
                    "7........", 
                    ".2.1.9...", 
                    "..7...24.", 
                    ".64.1.59.", 
                    ".98...3..", 
                    "...8.3.2.", 
                    "........6", 
                    "...2759..",
        });
        s.solveSudoku(board);
        printBoard(board);
    }
}
Esempio n. 2
0
}
constexpr Board buildBoardScan(int N, int Col, int Row, const Board &B) {
  return Row == N ? Board(0, true) :
         B.ok(Row, Col) ?
         tryBoard(buildBoardRecurse(N, Col + 1, B.addQueen(Row, Col)),
                  N, Col, Row+1, B) :
         buildBoardScan(N, Col, Row + 1, B);
}
constexpr Board buildBoardRecurse(int N, int Col, const Board &B) {
  return Col == N ? B : buildBoardScan(N, Col, 0, B);
}
constexpr Board buildBoard(int N) {
  return buildBoardRecurse(N, 0, Board());
}

constexpr Board q8 = buildBoard(8);

constexpr bool Board::check(const char *p, int Row, int Col) {
  return
    *p == '\n' ? check(p+1, Row+1, 0) :
    *p == 'o' ? at(Row, Col) && check(p+1, Row, Col+1) :
    *p == '-' ? !at(Row, Col) && check(p+1, Row, Col+1) :
    *p == 0 ? true :
    false;
}
constexpr bool check = q8.check(
    "o-------\n"
    "------o-\n"
    "----o---\n"
    "-------o\n"
    "-o------\n"