Add coordinate-value-reverse function
This commit is contained in:
		
							
								
								
									
										10
									
								
								src/util.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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);
 | 
					  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;
 | 
					export type N = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user