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

Thursday, December 20, 2012

LearnStreet Sample Solution Sudoku Solver Project Method 7



function isCorrectBlock(sudoku, block) {
    // This function is very similar to the previous two above except
    // that you will again have to figure out how to index all the elements
    // in the 'sudoku' array for the block specified by the 'block' argument.
    // This function should return true if all the numbers from 1 to 9 are
    // in the block. It should return false if the block is incomplete or
    // contains duplicates.
    // REPLACE THIS CODE WITH YOUR isCorrectBlock() METHOD
    var returnValue = true;
    var blockCopy = [];
    for(var i=0; i<9; i++){
        for(var j=0; j<9; j++){
            if(getCellBlock(i,j)===block){
                blockCopy.push(sudoku[i][j]);
            }  
        }
    }
    blockCopy.sort();
    for(var i=1; i<=9; i++){
        if(blockCopy[i-1]!==i){
            returnValue = false;
        }
    }
    return returnValue;
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts