c++ - Sudoku generation: it goes in loop -


I'm trying to eliminate a sudoku generator algorithm, this is my C ++ code:

  Zero generated sudoku (num sudoku [] [n]) {int i, j, k; Int weight [n], n, old; // To clear the Sudoku matrix, it is for the -1 (i = 0; i & lt; N; i ++) (j = 0; j & lt; n; j ++) sudoku [i] [Ja] .value = -1; Generates Sudoku for // (i = 0; i & lt; n;) {for (j = 0; j & lt; n;) {k = 0; Clean (Vett, N); // vector fills with 1 old = sudoku [i] [j] .val; // saves the real value {if (k & lt; 9) {do {n = rand ()% 9 + 1; } While (looks (Vett, N, N)); // Generate n when it is already present in vett vett [k ++] = n; If (((((Sudoku, i, j, n) present)) & amp; amp; amp; amp; amp; (n = old)) {// if this row, column and The sub-matrix is ​​not present and it is different between the old value, this sudoku is fine [i] [j ++]. Val = n; If (J ==N) I ++; K = 10; }} And {sudoku [i] [j] .val = -1; If (h> 0) j--; Otherwise if (i> gt; 0) {j = N-1; I--; } K = 10; }} While (k   

It goes into the loop and I know the reason:

  2 7 6 | 9 1 3 4 5 8 4 3 9 5 7 2 * *   

In this example it generates 6-1 and then 1-6 where * and it never ends. But if I understand why this loop is, then I do not know the best way to correct it. Can anyone help me?

You have to go back and forth. There is no valid entry in the last cell of that second line I'm not sure that a greedy algorithm is going to work as a Sudoku generator. I try with a stack-tree based approach instead.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -