### Confusing Logic Error

I am trying to make a program to solve a special Sudoku puzzle. The rules are: 1) Whole numbers 0-9 are to be used, three times each, to fill a 5 x 6 grid. 2) No number may be greater than the one directly above. 3) The sum of the numbers in each 4 x 4 sub-grid formed must be a multiple of three. 4) There are 8 constant numbers (1-8) already chosen in various places in the grid. My idea is to put 0-9, three times, into a vector and then random_shuffle the vector. Then the program is to check against the rules sequentially. If any rule is broken, the shuffling is done again, and all the rules are checked against again. If a combination passes all the rules, it is displayed as a string of numbers, which I will then translate into the grid. If there is no solution, the program will never escape the loop (and I will have to shut it down myself). Unfortunately, the program does not display anything and does not get stuck in its loop. I cannot tell what the problem is, can someone please help me? Code below (sorry for the long and cumbersome code :( )!

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182`` ``````#include #include #include #include #include using namespace std; int main() { vectorpuzzleBox; puzzleBox.push_back(0); puzzleBox.push_back(0); puzzleBox.push_back(0); puzzleBox.push_back(1); puzzleBox.push_back(1); puzzleBox.push_back(1); puzzleBox.push_back(2); puzzleBox.push_back(2); puzzleBox.push_back(2); puzzleBox.push_back(3); puzzleBox.push_back(3); puzzleBox.push_back(3); puzzleBox.push_back(4); puzzleBox.push_back(4); puzzleBox.push_back(4); puzzleBox.push_back(5); puzzleBox.push_back(5); puzzleBox.push_back(5); puzzleBox.push_back(6); puzzleBox.push_back(6); puzzleBox.push_back(6); puzzleBox.push_back(7); puzzleBox.push_back(7); puzzleBox.push_back(7); puzzleBox.push_back(8); puzzleBox.push_back(8); puzzleBox.push_back(8); puzzleBox.push_back(9); puzzleBox.push_back(9); puzzleBox.push_back(9); int a = 0; while(a) { random_shuffle(puzzleBox.begin(), puzzleBox.end()); if((puzzleBox[4] == 7 && puzzleBox[7] == 8 && puzzleBox[11] == 6 && puzzleBox[14] == 2 && puzzleBox[15] == 4 && puzzleBox[18] == 5 && puzzleBox[23] == 1 && puzzleBox[25] == 3)) { if(puzzleBox[0] >= puzzleBox[6] && puzzleBox[6] >= puzzleBox[12] && puzzleBox[12] >= puzzleBox[18] && puzzleBox[18] >= 24 && puzzleBox[1] >= puzzleBox[7] && puzzleBox[7] >= puzzleBox[13] && puzzleBox[13] >= puzzleBox[19] && puzzleBox[19] >= puzzleBox[25] && puzzleBox[2] >= puzzleBox[8] && puzzleBox[8] >= puzzleBox[14] && puzzleBox[14] >= puzzleBox[20] && puzzleBox[20] >= puzzleBox[26] && puzzleBox[3] >= puzzleBox[9] && puzzleBox[9] >= puzzleBox[15] && puzzleBox[15] >= puzzleBox[21] && puzzleBox[21] >= puzzleBox[27] && puzzleBox[4] >= puzzleBox[10] && puzzleBox[10] >= puzzleBox[16] && puzzleBox[16] >= puzzleBox[22] && puzzleBox[22] >= puzzleBox[28] && puzzleBox[5] >= puzzleBox[11] && puzzleBox[11] >= puzzleBox[17] && puzzleBox[17] >= puzzleBox[23] && puzzleBox[23] >= puzzleBox[29]) { if(((puzzleBox[0] + puzzleBox[1] + puzzleBox[6] + puzzleBox[7])%3 == 0) && ((puzzleBox[1] + puzzleBox[2] + puzzleBox[7] + puzzleBox[8])%3 == 0) && ((puzzleBox[2] + puzzleBox[3] + puzzleBox[8] + puzzleBox[9])%3 == 0) && ((puzzleBox[3] + puzzleBox[4] + puzzleBox[9] + puzzleBox[10])%3 == 0) && ((puzzleBox[4] + puzzleBox[5] + puzzleBox[10] + puzzleBox[11])%3 == 0) && ((puzzleBox[6] + puzzleBox[7] + puzzleBox[12] + puzzleBox[13])%3 == 0) && ((puzzleBox[7] + puzzleBox[8] + puzzleBox[13] + puzzleBox[14]%3 == 0) && ((puzzleBox[8] + puzzleBox[9] + puzzleBox[14] + puzzleBox[15])%3 == 0) && ((puzzleBox[9] + puzzleBox[10] + puzzleBox[15] + puzzleBox[16])%3 == 0) && ((puzzleBox[10] + puzzleBox[11] + puzzleBox[16] + puzzleBox[17])%3 == 0) && ((puzzleBox[12] + puzzleBox[13] + puzzleBox[18] + puzzleBox[19])%3 == 0) && ((puzzleBox[13] + puzzleBox[14] + puzzleBox[19] + puzzleBox[20])%3 == 0) && ((puzzleBox[14] + puzzleBox[15] + puzzleBox[20] + puzzleBox[21])%3 == 0) && ((puzzleBox[15] + puzzleBox[16] + puzzleBox[21] + puzzleBox[22])%3 == 0) && ((puzzleBox[16] + puzzleBox[17] + puzzleBox[22] + puzzleBox[23])%3 == 0) && ((puzzleBox[18] + puzzleBox[19] + puzzleBox[24] + puzzleBox[25])%3 == 0) && ((puzzleBox[19] + puzzleBox[20] + puzzleBox[25] + puzzleBox[26])%3 == 0) && ((puzzleBox[20] + puzzleBox[21] + puzzleBox[26] + puzzleBox[27])%3 == 0) && ((puzzleBox[21] + puzzleBox[22] + puzzleBox[27] + puzzleBox[28])%3 == 0) && ((puzzleBox[22] + puzzleBox[23] + puzzleBox[28] + puzzleBox[29])%3 == 0))) { int b = 0; vector::iterator it = puzzleBox.begin(); while(it != puzzleBox.end()) { cout << puzzleBox[b] << " "; it++; b++; } break; } else { continue; } } else { continue; } } else { continue; } } }``````
 ``4546`` `````` int a = 0; while(a)``````
It should be obvious that the loop would never execute.
your while loop doesn't execute because you set a to 0
 ``12`` `````` int a = 0; while(a)``````

Wow, I feel like a complete idiot now! Thank you both for pointing it out!
Topic archived. No new replies allowed.