From 9742ed3c4af77b4b0d138ab00ea1cebe037878ef Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 2 Sep 2018 11:30:03 +0200 Subject: solve_bt_bfs: more powerful isValid --- solve_bt_bfs.cpp | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/solve_bt_bfs.cpp b/solve_bt_bfs.cpp index bf14218..672b167 100644 --- a/solve_bt_bfs.cpp +++ b/solve_bt_bfs.cpp @@ -70,52 +70,75 @@ static ostream& operator<<(ostream &os, const Sudoku &su) { return os; } +template static bool isValid(const Sudoku &su) { for (int y = 0; y < 9; y++) { int i = 9 * y; - uint8_t seen[9]; - memset(seen, 0, 9); + + uint16_t seen = 0; + uint16_t seenPoss = 0; + for (int x = 0; x < 9; x++, i++) { int v = su[i]; if (v != -1) { - if (seen[v]) return false; - else seen[v] = 1; + if (seen & (1<(item.su)) { // item.maxposs = calcMaxposs(item.su); item.init = {i, v}; qu.push_back(move(item)); @@ -335,7 +358,7 @@ static Resolution solve(const Sudoku &su) { item.su[i] = v; scratchAround(item.su, i); - if (isValid(item.su)) { + if (isValid(item.su)) { // item.maxposs = calcMaxposs(item.su); qu.push_back(move(item)); -- cgit v1.2.3