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
Post a Comment