Select Git revision
-
Jamie Magee authored
Co-authored-by:
Michael Kriese <michael.kriese@visualon.de>
Jamie Magee authoredCo-authored-by:
Michael Kriese <michael.kriese@visualon.de>
main.js 1.48 KiB
// Sudoku Solver
// Copyright (C) 2020 Christoph (Sheogorath) Kern
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
const Sudoku = require("./lib/sudoku");
const sudoku = new Sudoku();
const exampleSudoku = [];
exampleSudoku.push([0, 8, 0, 0, 0, 0, 0, 3, 0])
exampleSudoku.push([4, 0, 0, 3, 6, 8, 0, 0, 0])
exampleSudoku.push([3, 5, 0, 4, 0, 9, 7, 0, 0])
exampleSudoku.push([0, 0, 0, 0, 0, 3, 6, 5, 0])
exampleSudoku.push([0, 0, 3, 0, 0, 0, 9, 0, 0])
exampleSudoku.push([0, 7, 8, 1, 0, 0, 0, 0, 0])
exampleSudoku.push([0, 0, 4, 2, 0, 1, 0, 7, 6])
exampleSudoku.push([0, 0, 0, 8, 5, 6, 0, 0, 9])
exampleSudoku.push([0, 6, 0, 0, 0, 0, 0, 2, 0])
for(let i = 0; i < 9; i++) {
for(let j = 0; j < 9; j++) {
if (exampleSudoku[i][j] !== 0) {
sudoku.presetField(i+1, j+1, exampleSudoku[i][j])
}
}
}
console.log(sudoku.toString());
sudoku.solve();
console.log(sudoku.toString());