-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAadi.java
More file actions
58 lines (44 loc) · 1.61 KB
/
Copy pathAadi.java
File metadata and controls
58 lines (44 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Aadi {
public static void insert(int [][][] sud, int x, int y, int num){
sud[x][y][0] = num;
for ( int i = 0; i < 9;i++){
sud [x][i][num] = 1; // 1 -- means already used (not availible at this position
sud [i][y][num] = 1;
sud [x][y][i+1] =1 ;
}
int diagX = 3* (x/3) ; // using round down division to get the starting index of the sub box
int diagY = 3* (y/3) ;
for ( int i = diagX; i < diagX + 3; i ++){
for (int j = diagY; j < diagY + 3; j++){
sud[i][j][num] = 1;
}
}
}
public static void printSudoku (int [][][] sud){
for ( int i = 0; i < sud.length; i ++){
for ( int k = 0; k < sud[i].length; k ++){
if(sud[i][k][0] == 0) System.out.print ( " | ");
else System.out.print ( sud[i][k][0] + " | ");
}
System.out.println();
System.out.println("-----------------------------------");
}
}
public static int[][][] createBlank(){
int[][][] sud = new int [9][9][10];
for ( int i = 0; i < sud.length; i ++){
for ( int k = 0; k < sud[i].length; k ++){
for(int j = 0; j < sud[i][k].length; j++){
sud[i][k][j] =0;
}
}
}
return sud;
}
public static int[][][] main(String[] args){
int[][][] sud = createBlank();
insert(sud,2,2,3);
printSudoku(sud);
return sud;
}
}