Add value visualizer
This commit is contained in:
		
							
								
								
									
										26
									
								
								src/visualizeValues.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/visualizeValues.ts
									
									
									
									
									
										Normal 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("+---------+---------+---------+");
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user