From 35774c0f0b1b1bb88fb7fa670c75e087f002f888 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Mon, 10 Jun 2024 18:02:39 +0200 Subject: [PATCH] Add coordinate-value-reverse function --- src/util.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util.ts b/src/util.ts index 682e43f..af318b3 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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;