diff options
-rw-r--r-- | solve.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -133,6 +133,23 @@ private: recurseone(dst); } + bool verifyConsistent(bool diag=false) const { + for(int i=0;i<N;i++){ + bitset<N> seenH,seenV; + for(int j=0;j<N;j++){ + if(bd[i][j]!=-1){ + if(seenH.test(bd[i][j]-1)){if(diag)cerr<<__LINE__<<": ("<<j<<','<<i<<')'<<endl; return false;} + seenH.set(bd[i][j]-1); + } + if(bd[j][i]!=-1){ + if(seenV.test(bd[j][i]-1)){if(diag)cerr<<__LINE__<<": ("<<i<<','<<j<<')'<<endl; return false;} + seenV.set(bd[j][i]-1); + } + } + } + return true; + } + public: Sudoku(const string &init){ static_assert(N>1&&BW>1&&BH>1&&BW*BH==N,"Box size inconsistent"); @@ -166,23 +183,6 @@ public: return dst; } - bool verifyConsistent(bool diag=false) const { - for(int i=0;i<N;i++){ - bitset<N> seenH,seenV; - for(int j=0;j<N;j++){ - if(bd[i][j]!=-1){ - if(seenH.test(bd[i][j]-1)){if(diag)cerr<<__LINE__<<": ("<<j<<','<<i<<')'<<endl; return false;} - seenH.set(bd[i][j]-1); - } - if(bd[j][i]!=-1){ - if(seenV.test(bd[j][i]-1)){if(diag)cerr<<__LINE__<<": ("<<i<<','<<j<<')'<<endl; return false;} - seenV.set(bd[j][i]-1); - } - } - } - return true; - } - bool verifySolution(const Sudoku<N,BW,BH> &sol) const { for(int y=0;y<N;y++){ for(int x=0;x<N;x++){ |