Add coordinate-value-reverse function

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

View File

@ -8,4 +8,14 @@ export function v(x: number, y: number, w: number): number {
return x + 9 * (y - 1) + 81 * (w - 1);
}
export function getXYW(v: number): { x: number; y: number; w: number } {
assert(1 <= v && v <= 729);
const w = Math.floor((v - 1) / 81) + 1;
const y = (Math.floor((v - 1) / 9) % 9) + 1;
const x = ((v - 1) % 9) + 1;
return { x, y, w };
}
export type N = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;