UseOriginally posted by zzzjjj2002:My source code is indented correctly. But after pasting here, no indent at all.
Paste code here
public class T
{
int[][] a = {
{0,0,8,0,0,0,4,7,0},
{0,2,0,3,0,0,0,0,9},
{0,0,9,2,6,0,0,3,0},
{0,0,0,0,3,0,0,0,8},
{3,0,0,7,0,1,0,0,4},
{5,0,0,0,2,0,0,0,0},
{0,4,0,0,5,3,8,0,0},
{8,0,0,0,0,6,0,4,0},
{0,6,3,0,0,0,5,0,0} };
/* {0,0,8,0,0,3,0,0,0},
{0,3,5,0,0,9,6,0,0},
{2,4,0,0,0,0,0,0,5},
{3,0,2,0,0,6,0,0,7},
{0,8,0,0,0,0,0,5,0},
{5,0,0,1,0,0,3,0,6},
{7,0,0,0,0,0,0,8,3},
{0,0,3,7,0,0,9,6,0},
{0,0,0,8,0,0,7,0,0} };*/
boolean checkRow(int[][] aa, int i, int j, int n)
{
for(int k=0; k<9; k++)
{
if(aa[i][k] == n ) return false;
}
return true;
}
boolean checkColumn(int[][] aa, int i, int j, int n)
{
for(int k=0; k<9; k++)
{
if(aa[k][j] == n ) return false;
}
return true;
}
boolean checkSquare(int[][] aa, int i, int j, int n)
{
int k1 = i / 3;
int k2 = j / 3;
k1 *= 3;
k2 *= 3;
for(int x=0; x<3; x++ )
{
for(int y=0; y<3; y++ )
{
if(aa[k1+x][k2+y] == n ) return false;
}
}
return true;
}
void print(int[][] aa)
{
for(int x=0; x<9; x++)
{
for(int y=0; y<9; y++)
{
System.out.print(" "+aa[x][y]);
}
System.out.println();
}
System.out.println("=====================================" );
}
public static void main(String[] argv)
{
T t = new T();
int i = 0;
int j = 0;
int m = 1;
t.test(t.a,i,j,m);
}
void test(int[][] a, int i, int j, int m)
{
//System.out.println("i=" + i + " j=" +j + " m=" + m);
if( m > 9 ) return;
if( a[i][j] == 0 )
{
for(int x=m; x<=9; x++)
{
//System.out.println( "x=" + x);
if( checkRow(a,i,j,x) && checkColumn(a,i,j,x) && checkSquare(a,i,j,x) )
{
//System.out.println("" + x + " is tentatively accepted." );
int[][] aa = new int[9][9];
for(int xx=0; xx<9; xx++) for(int yy=0; yy<9; yy++) aa[xx][yy] = a[xx][yy];
aa[i][j] = x;
if(j<8 )
{
test(aa,i,j+1,1);
}
else
{
if(i<8 )
{
test(aa,i+1,0,1);
}
else
{
print(aa);
}
}
}
}
//System.out.println("rewinding..." ) ;
}
else
{
if(j<8 )
{
test(a,i,j+1,1);
}
else
{
if(i<8 )
{
test(a,i+1,0,1);
}
else
{
print(a);
}
}
}
}
}
if u can slay dragons, u can slay chicks.Originally posted by fugue in C minor:why learn "dragon-slaying'' skills? Why do it when computers do it better?
''dragon-slaying skills" is a metaphor that refers to obsolete skills or skills that are no longer useful. In our modern society, where got dragons to slay?Originally posted by Ito_^:if u can slay dragons, u can slay chicks.![]()
![]()
yes.Originally posted by fugue in C minor:''dragon-slaying skills" is a metaphor that refers to obsolete skills or skills that are no longer useful. In our modern society, where got dragons to slay?
Get it?![]()
for the best perfect solution to solving sudoku. for all empty spaces, u just write possible numbers down by eliminating the numbers horizontally, vertically and inside the box. u will need quite a few practices before u make no mistakes in filling in the numbers. and note that the flaw of this solution is u must make NO mistakes at all. after u managed to fill in all the empty spaces with possible numbers, u may want to solve either within the box, verically or horizontally. look for the empty spaces with only 1 possible number, or the number that only present at one space, that will be the correct number. following that, eliminate that number in all the spaces within the box, horizontally and vertically. repeat the process and there goes ur ans.Originally posted by zzzjjj2002:Do you ever try the "SUDOKU" puzzle that is published on TODAY every day?
The rules are easy. Fill in the grid so that every row, every column, and every 3X3 box contains the digits 1 through 9.
Example: 0 is the empty slot.
{0,0,8,0,0,0,4,7,0},
{0,2,0,3,0,0,0,0,9},
{0,0,9,2,6,0,0,3,0},
{0,0,0,0,3,0,0,0,8},
{3,0,0,7,0,1,0,0,4},
{5,0,0,0,2,0,0,0,0},
{0,4,0,0,5,3,8,0,0},
{8,0,0,0,0,6,0,4,0},
{0,6,3,0,0,0,5,0,0}.
Solution:
6 3 8 5 1 9 4 7 2
1 2 5 3 4 7 6 8 9
4 7 9 2 6 8 1 3 5
2 1 4 6 3 5 7 9 8
3 8 6 7 9 1 2 5 4
5 9 7 8 2 4 3 6 1
7 4 1 9 5 3 8 2 6
8 5 2 1 7 6 9 4 3
9 6 3 4 8 2 5 1 7
Please try today's puzzle:
{0,0,8,0,0,3,0,0,0},
{0,3,5,0,0,9,6,0,0},
{2,4,0,0,0,0,0,0,5},
{3,0,2,0,0,6,0,0,7},
{0,8,0,0,0,0,0,5,0},
{5,0,0,1,0,0,3,0,6},
{7,0,0,0,0,0,0,8,3},
{0,0,3,7,0,0,9,6,0},
{0,0,0,8,0,0,7,0,0}.
I will publish the computer program tomorrow.