Javascript recursion for sudoku? -


i working on sudoku puzzle, put items in array.
so, whenever invalid number, have call function recursively, cant that. can't understand problem id.

my methods are:

function checkvalidity(x,y) {     var number = math.floor((math.random()) * 10);     var validnumber = true;         (i = 0; < 9; i++) {             if (sudokuvaluearray[i][y] == number) {                 validnumber = false;             }         }         (i = 0; < 9; i++) {             if (sudokuvaluearray[x][i] == number) {                 validnumber = false;             }         }     if(validnumber==true) {         return number;     }     else if(validnumber == false) {      return   checkvalidity(x, y);     } } 

and second function is:

function createsudokesample() {     (var x = 0; x < 9; x++) {         (var y = 0; y < 9; y++) {            sudokuvaluearray[x][y] = checkvalidity(x, y);         }     } } 

by default had initilized sudokuvaluearray 0;

now how recursion?

you recursion work fine. problem code is unlikely algorithm use can produce valid sudoku.

at point becomes impossible find valid number recursion goes , goes until call stack exceeds.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -