-
-
Save sigh/2febe2a3c5f4cc24e30c74284a6c8ec5 to your computer and use it in GitHub Desktop.
Simple interface to https://sigh.github.io/Interactive-Sudoku-Solver/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="data/example_puzzles.js"></script> | |
<script src="js/util.js"></script> | |
<script src="js/sudoku_builder.js"></script> | |
<script> | |
var VERSION_PARAM=''; | |
var controller = {enableDebugOutput: ()=>null}; | |
</script> | |
<script src="js/debug.js"></script> | |
</head> | |
<body> | |
<textarea id="input" rows=4 cols=50></textarea> | |
<button id="solve">solve</button> | |
<div id="status"></div> | |
<div> | |
First solution: | |
<pre id="solution"></pre> | |
</div> | |
<div> | |
State: | |
<pre id="state"></pre> | |
</div> | |
</body> | |
<script> | |
const input = document.getElementById('input'); | |
const button = document.getElementById('solve'); | |
const solutionOutput = document.getElementById('solution'); | |
const stateOutput = document.getElementById('state'); | |
const statusOutput = document.getElementById('status'); | |
button.onclick = () => { | |
const text = input.value; | |
solutionOutput.textContent = ''; | |
stateOutput.textContent = ''; | |
let constraint; | |
try { | |
constraint = SudokuConstraint.fromText(text); | |
} catch (e) { | |
statusOutput.textContent = e; | |
return; | |
} | |
statusOutput.textContent = 'Solving...'; | |
window.setTimeout(async () => { | |
const solver = SudokuBuilder.build(constraint); | |
const result = await solver.nthSolution(0); | |
solutionOutput.textContent = result ? toShortSolution(result) : 'No solutions'; | |
await solver.nthSolution(1); // Try to find a second solution to prove uniqueness. | |
stateOutput.textContent = JSON.stringify(solver.state(), null, ' '); | |
statusOutput.textContent = ''; | |
}, 0); | |
}; | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment