Quotes help make search much faster. Example: "Practice Makes Perfect"

Thursday, December 20, 2012

LearnStreet Sample Solution Sudoku Solver Project Method 3



function isPossibleBlock(sudoku, block, number) {
    // A 'block' is a 3x3 area of the 'sudoku' in which numbers 1 to 9
    // must all be present. There are 9 of these zones in the Sudoku.
    // This method will return true if the 'number' argument is not already
    // in the block of the 'sudoku' specified by the 'block' argument --
    // again indicating a potentially legal move. (The 'sudoku' argument is,
    // as always, a 9x9 two-dimensional array.)
    // This method should return false if the 'number' already exists in the
    // specified 'block'.
    // The blocks are indexed from 0 to 8. The top row blocks being 0 to 2,
    // the middle row blocks being from 3 to 5 and the bottom row being 6 to 8.
    // Btw, the getCellBlock() function below might be helpful here.
    // REPLACE THIS CODE WITH YOUR isPossibleBlock() METHOD
    var returnValue = true;
    for(var i=0; i<9; i++){
        for(var j=0; j<9; j++){
            if(getCellBlock(i,j)===block && sudoku[i][j]===number){
                returnValue = false;
            }
        }
    }
    return returnValue;
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts