Add value visualizer

This commit is contained in:
Lukas | AstroGD 2024-06-10 18:02:52 +02:00
parent 35774c0f0b
commit bf46b3b454
Signed by: AstroGD
GPG Key ID: 82A5E6C236C535AA

26
src/visualizeValues.ts Normal file
View File

@ -0,0 +1,26 @@
import { getXYW } from "./util";
export function visualizeValues(values: number[]): void {
const sudoku: (number | null)[][] = Array.from({ length: 9 }, () => Array.from({ length: 9 }, () => null));
for (const value of values) {
const { x, y, w } = getXYW(value);
sudoku[y - 1]![x - 1] = w;
}
for (let y = 9; y > 0; y--) {
if (y % 3 === 0) {
console.log("+---------+---------+---------+");
}
for (let x = 0; x < 9; x++) {
if (x % 3 === 0) {
process.stdout.write("|");
}
process.stdout.write(sudoku[y - 1]![x] === null ? " " : " " + sudoku[y - 1]![x]!.toString() + " ");
}
console.log("|");
}
console.log("+---------+---------+---------+");
}