Skip to content

Instantly share code, notes, and snippets.

@tonymtz
Created October 19, 2017 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymtz/a546d7184d7cc85ff270d8f714e1d67b to your computer and use it in GitHub Desktop.
Save tonymtz/a546d7184d7cc85ff270d8f714e1d67b to your computer and use it in GitHub Desktop.
Fills a block with zeros given the block number, hardcoded for a sudoku grid.
// Fills a block with zeros given the block number, hardcoded for a sudoku grid.
// The "grid" must be a lineal array and must have 81 elements exactly.
// how to use it...
let grid = fillBlock(sudokuStoreMock.grid, 4);
function fillBlock(grid, blockNumber) {
let newGrid = grid.slice(0, grid.length);
blockNumber = blockNumber || 0;
let startPoints = [0, 3, 6, 27, 30, 33, 52, 55, 58];
/*
* 0 3 6
* 27 30 33
* 52 55 58
*/
let pointer = startPoints[blockNumber];
for (let index = 0; index < 9; index += 1) {
newGrid[pointer] = 0;
if ((pointer + 1) % 3 === 0 && pointer !== startPoints[blockNumber]) {
pointer = pointer + 6;
}
pointer++;
}
return newGrid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment